// 取得本機的IpHostEntry類別實體,MSDN建議新的用法
IPHostEntry iphostentry = Dns.GetHostEntry(Dns.GetHostName());
// 取得所有 IP 位址
foreach (IPAddress ipaddress in iphostentry.AddressList)
{
// 只取得IP V4的Address
if (ipaddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
Console.WriteLine("Local IP: " + ipaddress.ToString());
}
}
沒有留言:
張貼留言