Will The Real IP Address Please Stand Up?
- 0
- Add a Comment
There is a question that seems to plague some folks. When you go to a Web site on the Internet like whatsmyip.org, you see a number representing the IP address that Web site sees you as. If you happen to be a developer and you attempt to pull the IP address from your computer, sometimes you see a different number. A little C# snippet below shows you how to do this:
Step 1: Create a new Windows application.
Step 2: Add a line “using System.Net” to your list of imports.
Step 3: Add a list box control to your form.
Step 4: Add a button control to your form and double-click it. Enter the code below:
private void button1_Click(object sender, EventArgs e) {
listBox1.Items.Clear();
// Get the hostname
listBox1.Items.Add System.Net.Dns.GetHostName());
// Get the IPHost hostname
IPHostEntry IPHost = Dns.GetHostByName(Dns.GetHostName());
listBox1.Items.Add("My IP address is " + IPHost.AddressList[0].ToString()); }
This shows you the host name and IP address your PC thinks it is, why do these numbers (Web site IP address and PC IP address) not match up? If you are using a high-speed connection, your modem probably has its own IP Address. That’s it!
