Getting external IP Address

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, im using this code to get a computers IPAddress

Net.Dns.GetHostEntry(Net.Dns.GetHostName()).AddressList(0)

but that only gets the Lan IPAddress....how can i get the internet IP address?
 
sorry about the double post....i got an error the first time i tried to post,
but apparently it went through anyway
 
iwdu15 said:
sorry about the double post....i got an error the first time i tried to
post,
but apparently it went through anyway


No worries. Can't specifically answer your question, because the problem is,
it depends how you connect.
If you go through any kind of router/nat setup, the external address is
effectively unknown to your PC. It sends requests to it's default gateway
which then processes them. There are lots of websites out there (such as
www.whatsmyip.net) that can pick up the external address, so maybe you need
to look at somehow sending a request to one of these and processing it?
 
yea...i saw alot of things on that after doing a google search....i was
wondering, would connecting a socket to the same computer then checking the
remote end point work? i just want to avoid using any websites incase they
are unavailable for some reason....
 
iwdu15 said:
yea...i saw alot of things on that after doing a google search....i was
wondering, would connecting a socket to the same computer then checking
the
remote end point work? i just want to avoid using any websites incase they
are unavailable for some reason....

Do you mean connecting to "yourself"? I don't think so, as it would be
clever enough to realise that it is within the local segment... the gateway
(and beyond) is only accessed when the computer doesn't "know" how to get to
the destination you give it - so anything on the same subnet will connect
"directly" (for want of a better phrase), whereas anything else will go to
the gateway...
Now, I guess you could try pinging a completely random address and not worry
if it's there or not, and see if the reply (from the gateway and whatever
it's gateway is) gives any information as to the external address? I'm not
sure it will, but perhaps worth a go - effectively you need to work out how
to do a traceroute... then it shouldn't matter if the remote site is up or
down.
I don't have code for doing that however, but a google may turn up
something...
James.
 
Back
Top