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

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;

namespace Pxkt_Service
{
    
public partial class DomainToIp : Form
    
{
        
public DomainToIp()
        
{
            InitializeComponent();
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            
string strDomain = textBox1.Text.ToString();
            IPHostEntry hostEntry 
= Dns.GetHostEntry(strDomain);
            IPEndPoint ipEndPoint 
= new IPEndPoint(hostEntry.AddressList[0], 0);
        
string ipAddress = ipEndPoint.Address.ToString();
            textBox1.Text 
= ipAddress;
        }

    }

}
 
posted @ 2007-09-10 17:42  宿远  阅读(175)  评论(0)    收藏  举报