C#实现根据域名查询ip实例(原创)

using System;
using System.Net;
using System.Net.Sockets;

namespace GetIpByDomain
{
///

1<summary>   
2/// Class1 的摘要说明。   
3/// </summary>

class Class1
{
///

1<summary>   
2/// 应用程序的主入口点。   
3/// </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

 1<domain>\n");   
 2Console.Write("Example:\n");   
 3Console.Write(" GetIpByDomain.exe Www.ToEmpire.Com");   
 4}   
 5else   
 6{   
 7string strDomain = args[0].ToString();   
 8IPHostEntry hostEntry = Dns.Resolve(strDomain);   
 9IPEndPoint ipEndPoint = new IPEndPoint( hostEntry.AddressList[0],0);   
10//这就是你想要的   
11string ipAddress = ipEndPoint.Address.ToString();   
12Console.Write(ipAddress);   
13}   
14}   
15}   
16}   
17  
18我只是简单的实现一下,有兴趣的朋友可以改改Bug。</domain>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus