using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Net;
//需要引用.Net命名空间
namespace
ConsoleApplication1
{
class
Program
{
static
void
Main(
string
[] args)
{
//获得主机名
string
HostName = Dns.GetHostName();
Console.WriteLine(
"主机名是:"
+HostName);
//遍历地址列表,如果电脑有多网卡只能这样遍历显示
IPAddress[] iplist=Dns.GetHostAddresses(HostName);
for
(
int
i = 0; i < iplist.Length; i++)
{
Console.WriteLine(
"IP地址:"
+iplist[i]);
}
Console.ReadLine();
}
}
}