0

I'm trying to implement a socket application for my very frist time. WHen I use:

IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress = ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

the localEndPoint IPEndPoint contains "192.168.56.1", that is my address under my VirtualBox network. It should contain my local network ip ("192.168.1.165").

How can I manage it?

I looked over Google but I could find an answer sorry...

jop1
  • 1

2 Answers2

1

Your virtual machine doesn't know anything about the network interfaces in the outside world. You can only find out your local addresses with the NetworkInterface.GetAllNetworkInterfaces() method (see here). Anything else should be a configuration setting.

Community
  • 1
  • 1
fejesjoco
  • 11,763
  • 3
  • 35
  • 65
  • I am not INTO a virtual machine. I am on my machine where I installed VirtualBox. It creates its own virtual network, but I am not using it at all. – jop1 Dec 07 '14 at 18:01
  • Oh, I see. Well, when you have VirtualBox, you have multiple local interfaces, and hence multiple local addresses. You can still use the method that I mentioned in the answer. Then you can get the IP properties of each interface to see which one has a default gateway, and generally that is the interface you are looking for. Do note that any single machine can have zero or any number of multiple outgoing IP addresses. – fejesjoco Dec 07 '14 at 18:47
1

Use IPAddress.Any to simply bind on all local interfaces. You do not need to find out a specific local IP for most scenarios.

Note, that you are throwing away all but one address. No wonder that you are only getting one.

There is no such thing as the local IP. It is a set.

usr
  • 168,620
  • 35
  • 240
  • 369