Knowing Ip address of my client
Hi, I need to know IP address of my clients applications. I thought that i could get them by RemoteEndPOint, but when I did some test, I realized that I won't be able to do it through that way. This is what I did (just as an example):
Dim IP As New IPEndPoint("127.0.0.1", 8050)
IP.ToString 'Returns 25.240.1.0:8050
IP.Address.ToString 'Returns 25.240.1.0
IP.Address.Address.ToString 'Returns 127001
So, noting that I don't have any way to get the ip address from an IPEndPoint, how can i know it?. Another thing I don't understand is if I created an IPEndPoint with 127.0.0.1 as IPAddress, why it returns 25.240.1.0?.
Thank you very much.
Re: Knowing Ip address of my client
I did this a couple of times in VB6, but i dont know all the functions of .Net yet.
Anyway, i did this by fetching the ip address from http://Whatismyip.com and then
send it to my "server" app...
Re: Knowing Ip address of my client
It's probably getting the IP address attached to your network adapter. Try this. Go to Start -> Run and type in 'cmd' and press return. Now type in ipconfig. The IP addresses that it lists, is one of them the 25.240.x.x address?
Re: Knowing Ip address of my client
Hi, thanks for answer.
Phreak: How did you do that? Did you need some kind of HTML parser or something like that?
Kasracer: No, none of them is that ip address. Isn't that weird?
Regards!.
Re: Knowing Ip address of my client
Well i added i downloaded the source from the whatismyip site to a textbox
(can also be a string) and then i extracted the ip address from the HTML source.
And then i had the IP address :)
#Phreak :afrog:
Re: Knowing Ip address of my client
To answer the second question, IPEndPoint doesn't accept the string notation of the IP address. It's assuming that the value you passed is in the long format.
If you want to use the string format in the constructor, you need to parse it:
Dim IP As New IPEndPoint(net.ipaddress.parse("127.0.0.1"), 8050)
Re: Knowing Ip address of my client
are you taking into account that they might be behind a router and the IP address assigned to the PC could be a local internal IP, and not the actual WAN IP? This is usually the case these days.
Re: Knowing Ip address of my client
kleinma is right.... *(Again ;) )*
Re: Knowing Ip address of my client
If you would rather do your own conversion, this should help you out.
Also, if you use the example I gave, tostring will give you your "127.0.0.1" and GetHashCode will give you the long format (16777343).