IP LookUp Program in Asp.Net

Description:- 

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.

Name Spaces:-


using System;
using System.IO;
using System.Drawing;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Text;

Code:-

        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(button1_Click);
            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(button2_Click);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            address = txtBox1.Text;
            GetIP(address);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        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 static void Main()
        {
            Application.Run(new IPLookUp());
        }

Related Posts

Previous
Next Post »

Thanks for comments.....