您的位置:首页 > 其它

域名IP查寻的小工具

2007-05-05 18:30 183 查看
主要代码如下:
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;

namespace ip2domain
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CenterToScreen();
}

public bool checkip(string IP)
{

string[] vList = IP.Split('.');

if (vList.Length != 4) return false;

for (int j = 0; j < vList.Length; j++)
{

int i;

if (!int.TryParse(vList[j], out i))
return false;

if ((i < 0) || (i > 254))
return false;

if ((i == 0) && (j == 0))
return false;

}

return true;

}

IPHostEntry iphost;

private void button_ok_Click(object sender, EventArgs e)
{
try
{
if (textBox_input.Text != "")
{

listBox1.Items.Clear();
iphost = Dns.GetHostEntry(textBox_input.Text);
string hostname = iphost.HostName;
listBox1.Items.Add("主机名: " + hostname);
listBox1.Items.Add("");
for (int i = 0; i < iphost.AddressList.Length; i++)
{
IPEndPoint ipend = new IPEndPoint(iphost.AddressList[i], 0);
IPAddress ip = ipend.Address;
string ips = ip.ToString();
if (ips != "")
{
listBox1.Items.Add(ip);
listBox1.Items.Add("");
}
else
{
MessageBox.Show("No ip infomation!");
}
}
}

//else
//{
// MessageBox.Show("There must be some wrong!Please retry!");

// textBox_input.Text = "";
//}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
textBox_input.Text = "";
}

}

private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Clear();
bool ck = checkip(textBox_input.Text);
if (!ck)
{
MessageBox.Show("您输入有误!");
textBox_input.Text = "";
}
else
{
iphost = Dns.GetHostEntry(textBox_input.Text);
listBox1.Items.Add(iphost.HostName);
}
}

private void textBox_input_MouseEnter(object sender, EventArgs e)
{
textBox_input.SelectAll();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: