Results 1 to 15 of 15

Thread: How do I get my internet IP?

  1. #1

    Thread Starter
    Member nci's Avatar
    Join Date
    Aug 2003
    Posts
    43

    How do I get my internet IP?

    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

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do I get my internet IP?

    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.

  3. #3
    New Member
    Join Date
    Dec 2006
    Posts
    6

    Re: How do I get my internet IP?

    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

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How do I get my internet IP?

    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.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: How do I get my internet IP?

    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

  6. #6

    Re: How do I get my internet IP?

    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
    Last edited by evan29; Dec 13th, 2006 at 04:23 AM.

  7. #7
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do I get my internet IP?

    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.

  8. #8
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: How do I get my internet IP?

    @RD,
    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.)
    Last edited by iPrank; Dec 10th, 2006 at 01:38 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  9. #9
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do I get my internet IP?

    Oh, there are sites returning stuff easier to parse than that:

    Code:
    <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!

  10. #10
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: How do I get my internet IP?

    Quote Originally Posted by dilettante
    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?

  11. #11
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do I get my internet IP?

    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.

  12. #12
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: How do I get my internet IP?

    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.

  13. #13
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: How do I get my internet IP?

    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.

  14. #14
    Lively Member
    Join Date
    Oct 2006
    Location
    Error!
    Posts
    103

    Re: How do I get my internet IP?

    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.

    Quote Originally Posted by DigiRev
    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.

  15. #15
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: How do I get my internet IP?

    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)
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width