如何让一台机器在C#中的IP地址 [英] How to get the IP address of a machine in C#
本文介绍了如何让一台机器在C#中的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何得到一台机器的IP地址,在C#?
解决方案
ip地址[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
您的设备没有一个单一的IP地址,以及一些返回的地址可以是IPv6的
MSDN链接:
- <一个href="http://msdn.microsoft.com/en-us/library/system.net.dns.gethostaddresses%28lightweight%29.aspx">Dns.GetHostAddresses
- <一个href="http://msdn.microsoft.com/en-us/library/system.net.ipaddress%28lightweight%29.aspx">IPAddress
另外,如 MSalters 的提及, 127.0.0.1
/ :: 1
的环回地址,然后将总是指本地计算机。由于明显的原因,但是,它不能被用于从一个远程设备连接到本地计算机。
How do I get the IP address of a machine in C#?
解决方案
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
Your machine doesn't have a single IP address, and some of the returned addresses can be IPv6.
MSDN links:
Alternatively, as MSalters mentioned, 127.0.0.1
/ ::1
is the loopback address and will always refer to the local machine. For obvious reasons, however, it cannot be used to connect to the local machine from a remote machine.
这篇关于如何让一台机器在C#中的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文