【获取IP】
一:适用于单网卡情形
string hostInfo = Dns.GetHostName();
//IP地址
//System.Net.IPAddress[] addressList = Dns.GetHostByName(hostInfo).AddressList;这个过时
System.Net.IPAddress[] addressList = Dns.GetHostEntry(hostInfo).AddressList;
ip = addressList[0].ToString();
二:适用于多网卡情形
foreach (NetworkInterface netInt in NetworkInterface.GetAllNetworkInterfaces())
{
IPInterfaceProperties property = netInt.GetIPProperties();
foreach (UnicastIPAddressInformation ip in property.UnicastAddresses)
{
if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
ipaddr &