using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
namespace GETIP
{
class Program
{
static void Main(string[] args)
{
IPHostEntry IPHost;
try
{
if (args.Length == 0)
IPHost = Dns.GetHostEntry("localhost");
else if (args[0] == "/?" || args.Length != 1)
{
Console.WriteLine("格式:GetIP [主机名|/?]");
return;
}
else
IPHost = Dns.GetHostEntry(args[0]);
Console.WriteLine("主机的DNS名称" + IPHost.HostName);
string[] aliases = IPHost.Aliases;
Console.WriteLine("该主机有{0}个别名:",aliases .Length );
for (int i = 0; i < aliases.Length; i++)
{
Console.WriteLine(aliases );
}
IPAddress[] addr = IPHost.AddressList;
Console.WriteLine("该主机拥有{0}个IP地址", addr.Length);
for (int i = 0; i < addr.Length; i++)
{
Console.WriteLine("addr");
}
}
catch (System.Net.Sockets.SocketException e)
{
Console.WriteLine(" 错误的主机名!");
}
catch (Exception e)
{
Console.WriteLine(e.Message .ToString ());
}
}
}
}
代码编辑环境为visual studio 2005 C#
|