using System;
using System.Net;
namespace GetIpAndName
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
//得到主机名
string name = Dns.GetHostName();
Console.WriteLine("主机名字:{0}",name);
IPHostEntry me = Dns.GetHostByName(name);
//输出得到的IP
foreach (IPAddress ip in me.AddressList)
{
Console.WriteLine("IP 地址:{0}",ip.ToString());
}
Console.ReadLine();
}
}
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7257938/viewspace-837668/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7257938/viewspace-837668/