MainCodeAs follows:
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 ("Host Name:" + 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 button#click (Object sender, eventargs E)
{
Listbox1.items. Clear ();
Bool ck = checkip (textbox_input.text );
If (! CK)
{
MessageBox. Show ("your input is incorrect! ");
Textbox_input.text = "";
}
Else
{
Iphost = DNS. gethostentry (textbox_input.text );
Listbox1.items. Add (iphost. hostname );
}
}
private void textbox_input_mouseenter (Object sender, eventargs e)
{< br> textbox_input.selectall ();
}< BR >}