private string GetHostNameAndIP( bool isv4Orv6)
{
string HostName = Dns.GetHostName();//本机名
string IPAddress = "";
System.Net.IPAddress[] addressList = Dns.GetHostAddresses(HostName);//会返回所有地址,包括IPv4和IPv6
foreach (IPAddress ip in addressList)
{
if (isv4Orv6)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
IPAddress = ip.ToString();
}
else
{
if (ip.AddressFamily == AddressFamily.InterNetworkV6)
IPAddress = ip.ToString();
}
}
return "{HostNmae:'" + HostName + "',Ip:'" + IPAddress + "'}";
}