有谁知道在.NET Framework中哪个类可以有取得本机IP地址的方法?
有谁知道在.NET Framework中哪个类可以有取得本机IP地址的方法。 问题点数:50、回复次数:2Top
1 楼jiezhi(风满袖)回复于 2003-09-03 10:08:16 得分 25
System.Net
using System;
using System.Net;
public class DNSUtility
{
public static int Main (string [] args)
{
String strHostName = new String ("");
if (args.Length == 0)
{
// 首先得到本地机器的主机名称
strHostName = Dns.GetHostName ();
Console.WriteLine ("Local Machine's Host
Name: " + strHostName);
}
else
{
strHostName = args[0];
}
// 然后通过主机名称得到IP地址列表
IPHostEntry ipEntry = Dns.GetHostByName
(strHostName);
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine ("IP Address {0}: {1} ", i,
addr[i].ToString ());
}
return 0;
}
}
Top
2 楼jiezhi(风满袖)回复于 2003-09-03 10:08:35 得分 25
System.Net
using System;
using System.Net;
public class DNSUtility
{
public static int Main (string [] args)
{
String strHostName = new String ("");
if (args.Length == 0)
{
// 首先得到本地机器的主机名称
strHostName = Dns.GetHostName ();
Console.WriteLine ("Local Machine's Host
Name: " + strHostName);
}
else
{
strHostName = args[0];
}
// 然后通过主机名称得到IP地址列表
IPHostEntry ipEntry = Dns.GetHostByName
(strHostName);
IPAddress [] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine ("IP Address {0}: {1} ", i,
addr[i].ToString ());
}
return 0;
}
}
Top
3 楼rouser(流淌的小溪)回复于 2003-09-03 10:08:38 得分 0
System.Net.Dns.GetHostByName("你機器的名字").AddressList[1].AddressTop




