IP addresses

G

Guest

I wrote I short program to get my machine's ip:
And everytime I get an odd result, which I don't understand:
I keep getting a list of 3 IP numbers, the first one never changes.
The second and the third are the same numbers but they change everytime I
disconnect and reconnect to the internet.
Here is the code:
Socket reciever= new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
IPAddress ipAddress=ipHostInfo.AddressList[0];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11102);

foreach(IPAddress i in ipHostInfo.AddressList)
Console.WriteLine(i.ToString());


The other odd thing is when I write a Client program which tries to coonect
to my machine I succeed to do so only when I use the first ip from the list,
which never changes, when I try to use the other IP nothing happans.
I do it through the function: IPAddress ipAddress = IPAddress.Parse(my ip
which changes every reconnection);

What is this Constant IP number, why do I get a list of 3 IPs and why can't
I coonect to the changing IP?
Thanks for your help
 
J

Joris Dobbelsteen

If the non-changing number is 127.0.0.1, this is your 'loopback' address
that all computers have. It will always point to the local computer. Or
perhaps it you local network card.
The second is probably something like 81.x.x.x, which is the Internet IP you
get from your Internet provider.

Please send the IPs you get (you can leave the last 2 numbers to yourself)


Anyway, this code is very odd, you should NOT specificy an address with the
end-point if you want to bind to ALL network cards. This can and should be
done with a single socket.

If you type (in the command prompt) "netstat -a -p TCP", you might see a
list, look for ones that are "LISTENING"
0:0:0:0 - all interfaces
127:0:0:1 - computer local only
others are to specific network cards.


- Joris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top