Welcome

首页 / 软件开发 / C# / C#实现根据域名查询ip实例

C#实现根据域名查询ip实例2010-06-25using System;
using System.Net;
using System.Net.Sockets;
namespace GetIpByDomain
{
/// <summary>
/// Class1 的摘要说明.
/// </summary> class Class1
{
/// <summary>
/// 应用程序的主入口点.
/// </summary> [STAThread] static void Main( string[] args )
{
//
// TODO: 在此处添加代码以启动应用程序
//
if( args.Length <= 0 ) { Console.Write( " GetIpByDomain V1.0 by ∮明天去要饭 QQ:305725744 " );
Console.Write( "Usage: " );
Console.Write( " GetIpByDomain.exe <Domain> " );
Console.Write( "Example: " );
Console.Write( " GetIpByDomain.exe Www.ToEmpire.Com" );
}
else
{
string strDomain = args[0].ToString( );
IPHostEntry hostEntry = Dns.Resolve( strDomain );
IPEndPo
int ipEndPo
int = new IPEndPo
int(hostEntry.AddressList[0],0 );
//这就是你想要的
string ipAddress = ipEndPo
int.Address.ToString( );
Console.Write( ipAddress );
}
}
}
}

我只是简单的实现一下,有兴趣的朋友可以改改Bug.