SIGN UP MEMBER LOGIN:    
ARTICLE

IP LookUp Program in .NET

Posted by Michael Marasco Articles | Internet & Web April 03, 2002
This is an IP look up program that uses C# Windows Forms and IPHostEntry to resolve the DNS request.
Reader Level:

This is an IP look up program that uses C# Windows Forms and IPHostEntry to resolve the DNS request. You enter the URL in the first box and press the Look Up button and the IP shows in the bottom box.

I created the controls, instead of using the form designer and in doing so the placement is not that great. But it should give a very basic example of creating your own controls and how the IPHostEntry works.

using System;
using System.IO;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Text;
class IPLookUp : Form
{
TextBox txtBox1;
TextBox txtBox2;
string address;
string IPaddress;
public IPLookUp()
{
Text = "IP Look Up";
BackColor = Color.White;
txtBox1 =
new TextBox();
txtBox1.Parent =
this;
txtBox1.Text = "Enter URL";
txtBox1.Location =
new Point(Font.Height * 6, Font.Height * 2);
Button btnlook =
new Button();
btnlook.Parent =
this;
btnlook.BackColor = SystemColors.ControlDark;
btnlook.Text = "Look UP";
btnlook.Location =
new Point(Font.Height * 7, Font.Height * 6);
btnlook.Click +=
new EventHandler(ButtonOnClick);
Label label =
new Label();
label.Parent =
this;
label.Text = "IP Address";
label.Location =
new Point(Font.Height * 6, Font.Height * 10);
txtBox2 =
new TextBox();
txtBox2.Parent =
this;
txtBox2.Text = " ";
txtBox2.Location =
new Point(Font.Height * 6, Font.Height * 12);
Button btnquit =
new Button();
btnquit.Parent =
this;
btnquit.BackColor = SystemColors.ControlDark;
btnquit.Text = "Quit";
btnquit.Location =
new Point(Font.Height * 7, Font.Height * 16);
btnquit.Click +=
new EventHandler(ButtonQuitOnClick);
}
public void ButtonOnClick(object sender, EventArgs ea)
{
address = txtBox1.Text;
GetIP(address);
}
private void GetIP(string address)
{
try
{
IPHostEntry IPHost = Dns.Resolve(address);
IPAddress[] addresses = IPHost.AddressList;
IPaddress = addresses[0].ToString();
txtBox2.Text = IPaddress;
}
catch(Exception exc)
{
MessageBox.Show(exc.ToString());
}
}
public void ButtonQuitOnClick(object sender, EventArgs ea)
{
Application.Exit();
}
public static void Main()
{
Application.Run(
new IPLookUp());
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor