您的位置:首页 > 编程语言 > C#

C#实现根据域名查询ip实例

2007-05-12 15:54 816 查看
using 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("/nGetIpByDomain V1.0 by ∮明天去要饭 QQ:305725744/n");
Console.Write("Usage:/n");
Console.Write(" GetIpByDomain.exe <Domain>/n");
Console.Write("Example:/n");
Console.Write(" GetIpByDomain.exe Www.ToEmpire.Com");
}
else
{
string strDomain = args[0].ToString();
IPHostEntry hostEntry = Dns.Resolve(strDomain);
IPEndPoint ipEndPoint = new IPEndPoint( hostEntry.AddressList[0],0);
//这就是你想要的
string ipAddress = ipEndPoint.Address.ToString();
Console.Write(ipAddress);
}
}
}
}

我只是简单的实现一下,有兴趣的朋友可以改改Bug。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: