How to get the client IP address?
-
Hello everyone, I am trying to get the IP Address of the client so the application can hook itself up to it. I am using the following code:
private void MyApplicationForm\_Load(object sender, EventArgs e) { string strIP = null; IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName())); if (HosyEntry.AddressList.Length > 0) { foreach (IPAddress ip in HosyEntry.AddressList) { strIP = ip.ToString(); cmbInterfaces.Items.Add(strIP); } } }
When I run the application on my PC which is connected via a cable to a routher I only get on IP address which is the internal IP address. But when I run the Application on my laptop which is using Wireless Connection to the same routher I get list of few IP addresses. Can someone tell me why this is the case and how can I make sure I only the IP address that my laptop is set to rather than the list of the IP addresses. Thank you very much and have a great day.
-
Hello everyone, I am trying to get the IP Address of the client so the application can hook itself up to it. I am using the following code:
private void MyApplicationForm\_Load(object sender, EventArgs e) { string strIP = null; IPHostEntry HosyEntry = Dns.GetHostEntry((Dns.GetHostName())); if (HosyEntry.AddressList.Length > 0) { foreach (IPAddress ip in HosyEntry.AddressList) { strIP = ip.ToString(); cmbInterfaces.Items.Add(strIP); } } }
When I run the application on my PC which is connected via a cable to a routher I only get on IP address which is the internal IP address. But when I run the Application on my laptop which is using Wireless Connection to the same routher I get list of few IP addresses. Can someone tell me why this is the case and how can I make sure I only the IP address that my laptop is set to rather than the list of the IP addresses. Thank you very much and have a great day.
Hi! I think you have a basic misconception here: Any given PC doesn't have "the one IP address", it all depends on the network connections you have. Worst case: No network at all, so the PC doesn't have an IP address at all. In all the other cases, each network interface can (and usually will) have a different IP address. Try opening a command shell and executing "ipconfig /all", you'll see the settings and IP addresses for all the network interfaces.
Regards, mav -- Black holes are the places where God divided by 0...