Click to See Complete Forum and Search --> : How do I get my internet IP?
nci
Dec 8th, 2006, 11:22 AM
Hi
I've been trying to figure out how to get my internet IP Address so that a computer over the internet can connect to my computer. Anyone know how to get the IP Address?
Thanks
dilettante
Dec 8th, 2006, 01:34 PM
I can think of two obvious ways.
One involves "asking" the NAT device via one of its admin services. Some will allow a simple Telnet-style connection, almost all allow HTTP queries via port 80 from internal hosts. Either way your application will need to know (a.) that there is a NAT device present and (b.) how to talk to it.
The other involves an external service of some sort that will echo back the public IP address when queried. Many dynamic DNS providers offer this but I hesitate to list a URL because I'm sure they don't want non-customers banging away at their servers.
Another possible method might be to perform a "traceroute" style operation that may come back with what you need, but fishing it out might be problematic. And perhaps the info you need isn't even returned... it isn't displayed as part of a standard traceroute utility's report anyway.
I hope this helps. If not maybe someone else can offer a better solution.
basiliou
Dec 8th, 2006, 04:17 PM
Sorry Guys, I'm complete new to this fantastic forum and a kind of newbie in VB programming.
Is there any problem to involve Winsock to get your local IP?
Unless i have not understand well, Winsock looks fine for me....
Regards
George
RobDog888
Dec 8th, 2006, 05:06 PM
Yes, winsock can do it but if you are behind a router then that will probably return the public router ip.
Go to http://whatismyip.com to determine the routers IP to check against.
DigiRev
Dec 9th, 2006, 09:34 AM
If you're on a network, Winsock.LocalIP will return your local (network) IP, ie:
192.168.0.1 or whatever it may be.
If you have no router/hub, then it should return your external IP.
The best bet would be like RobDogg said and get your external IP from a remote host like showmyip.com
evan29
Dec 10th, 2006, 06:44 AM
Hey this might wrap it up for you. Its for Visual Basic 6. I used it to find my IP. It finds it via winsock but if your behind a router, then it will not return your external IP.
http://support.microsoft.com/kb/160215
dilettante
Dec 10th, 2006, 11:00 AM
I your only worry is to have the program determine the local IP address then yes, checking via a Winsock control or the Winsock API works fine.
Otherwise (as in the case where your program may be running on a machine behind a NAT router) you'll probably have to query either the router or an external machine. Either way you'll need to know how to do the query and how to parse the IP address from the response.
I'm not aware of any standard universal way of doing this. Your program needs to either be very aware of the router or very aware of the specific host to be queried.
iPrank
Dec 10th, 2006, 12:27 PM
@RD,
http://whatismyip.org (http://whatismyip.org/) is easier to parse. (A simple URLDownloadToFile will do. But you need to clear browser cache first, in case of dynamic IPs.)
dilettante
Dec 10th, 2006, 12:51 PM
Oh, there are sites returning stuff easier to parse than that:
<html><head><title>Current IP Check</title></head><body>Current IP Address: 20.20.20.20</body></html>
The real issue is what would you even do with it once you had it?
Let's say you're trying to make a distributed game program. One guy starts up and plays "server" and three other guys start up to play as "client."
They all use some incantation to figure out their public IP addresses.
Ok, now they know their own IP addresses. But they have no idea what the IP address of any of the other guys is, so nobody can connect to anyone else!
DigiRev
Dec 10th, 2006, 03:59 PM
Ok, now they know their own IP addresses. But they have no idea what the IP address of any of the other guys is, so nobody can connect to anyone else!
That's the whole idea of having a server program in the first place.
They all connect to the server. The server is in charge of relaying packets back to the clients.
How do you think instant messenger programs (yahoo, MSN, etc.) work? Or games?
dilettante
Dec 11th, 2006, 10:09 AM
I guess I wasn't clear. I was sort of questioning the point of this whole thread:
Why figure out your own address from within the program? The other end will need it, or you'll need his, but knowing your own doesn't help much. If you're just going to call him on the phone and tell him you can use a plain old web response from one of those sites listed and read it off the screen.
DigiRev
Dec 11th, 2006, 05:57 PM
Oh I see what you're saying. :)
Well, there are alternatives, such as retrieving the IP, and then posting it onto a webpage (this could be done automatically).
The other clients could get the server IP from the webpage.
dilettante
Dec 11th, 2006, 06:00 PM
True that could be done. Or one or both people might register for a free dynamic DNS name at one of the many providers. Of course that means running an update client, but some routers have one built in and the PC-based ones are free.
Str4nger
Dec 18th, 2006, 03:36 PM
Why cant they just make a TCP connection with the server first which doesnt require the IP address of the client needed. Then the TCP connection sends the IP address as Data to the server and then the server connects to the IP address and also sends it to other clients for making a connection.
Oh I see what you're saying. :)
Well, there are alternatives, such as retrieving the IP, and then posting it onto a webpage (this could be done automatically).
The other clients could get the server IP from the webpage.
the182guy
Dec 18th, 2006, 05:01 PM
you can't connect to a server unless you know either the IP and port, or the domain name (if it has one) and port.
You can however, connect to your network machines using their computer name and port.
What you need to do is have a central server which all the clients connect to. Have it post the server IP to a webpage, then the clients can download the IP, then connect to it. They can then communicate with the other clients via the server. Thats how the messenger apps work (apart from storing the IP on a page, the big messenger apps have a domain name for the server, e.g. messenger.msn.com)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.