Results 1 to 22 of 22

Thread: finding the public IP

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Location
    Rotherham,UK
    Posts
    26

    finding the public IP

    with using vb6 how do i find the public ip NOT the local ip.
    thanks Frozenpost

  2. #2
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: finding the public IP

    You can use the Microsoft Internet Transfer control.

    Code:
    Private Sub Command1_Click()
        MsgBox Inet1.OpenURL("www.whatismyip.com/automation/n09230945.asp", icString)
    End Sub
    ::edit::

    Or if you don't want any extra independencies, then you can use API.

    In a module:

    Code:
    Option Explicit
    
    Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
    Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal sURL As String, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
    Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
    Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
    Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" (ByVal lpszUrlName As String) As Long
    
    Private Const IF_NO_CACHE_WRITE = &H4000000
    Private Const BUFFER_LEN = 256
    
    Public Function GetMyIP() As String
        Dim sBuffer As String * BUFFER_LEN, iResult As Integer, sURL As String
        Dim hInternet As Long, hSession As Long, lReturn As Long
    
        sURL = "http://www.whatismyip.com/automation/n09230945.asp"
        
        DeleteUrlCacheEntry sURL
        
        hSession = InternetOpen("vb wininet", 1, vbNullString, vbNullString, 0)
        If hSession Then hInternet = InternetOpenUrl(hSession, sURL, vbNullString, 0, IF_NO_CACHE_WRITE, 0)
    
        If hInternet Then
            iResult = InternetReadFile(hInternet, sBuffer, BUFFER_LEN, lReturn)
        End If
    
        iResult = InternetCloseHandle(hInternet)
    
        GetMyIP = sBuffer
    End Function
    In a Form:

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        MsgBox GetMyIP
    End Sub
    Last edited by Chris001; Dec 30th, 2007 at 02:04 PM.

  3. #3
    New Member
    Join Date
    Nov 2007
    Posts
    1

    Smile Re: finding the public IP

    Hi,
    Is there any way to get public IP without passing url. I mean apart from using "www.whatismyip.com" or any links.Is there any source to get it through vb.net.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: finding the public IP

    Welcome to the forums.

    Without a URL, how is the program supposed to know what IP it is supposed to be getting?

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    I assume you're looking for your own IP Address as far as the Internet is concerned, and you're behind a Router or similar device that has NAT enabled. A fairly simple way would be to use the technique suggested by Chris but accessing your device's Admin screens.

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    Doogle, That won't work all the time.

    The problem is that you need to be able to see your packet(s)once they make the jump from private-to-public. The receiver of your packet(s) knows your public IP.

    I have used checkip.dyndns.org url.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    When the Router connects to the Internet it is allocated an IP Address by the ISP. In most, if not all, Routers, this address is accessible from the Router Administrator's screen(s). This address will not change until a re-connection to the Internet is made. If it is a fixed address it will never change.

  8. #8
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    When the Router connects to the Internet it is allocated an IP Address by the ISP. - agree
    In most, if not all, Routers, this address is accessible from the Router Administrator's screen(s). - agree
    This address will not change until a re-connection to the Internet is made. If it is a fixed address it will never change. - I feel strongly both ways. It is not unusual for an ISP to allocate IP addresses using DHCP, some with definite expiration, some not.

    However, I think you ass-u-med something. The IP that the ISP assigned to your router may not (probably won't) be a public IP which is what the original post was about.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    Quote Originally Posted by dbasnett
    The IP that the ISP assigned to your router may not (probably won't) be a public IP ........
    Interesting. What will it be then? I am assigned an address by my ISP via DHCP and that is my IP Address as far as any other device on the Internet is concerned. I have many network applications that rely on that fact and they all work fine.

  10. #10
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    My IP address on the WAN side of my router, that is assigned by my ISP, is
    10.0.0.75. Most ISP's don't assign Public IP's, and if you need one a lot them charge for it.

    And it works, because as you mentioned in a previous post "... behind a Router or similar device that has NAT enabled."

    The only reliable method, as I and others have posted, is to get a reply from beyond the private / public interface.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  11. #11
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    Ah, I obviously don't understand what is meant by "Public IP".

    My ISP assigns me, say, an IP address of 80.123.45.65. That address is specified in the NIC interface in the Router to the outside world, Any device on the Internet wishing to communicate with me via IP will use that address. I had always assumed that was a "Public IP Address"

  12. #12
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    Quote Originally Posted by dbasnett
    Most ISP's don't assign Public IP's, and if you need one a lot them charge for it.
    That's a Static IP Address - ie the ISP assigns a fixed IP address to you rather than using DHCP. If you have a Static IP Address, then by definition, you know what it is because your ISP tells you and it never changes.

  13. #13
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    Read RFC1918, excerpt below

    3. Private Address Space

    The Internet Assigned Numbers Authority (IANA) has reserved the
    following three blocks of the IP address space for private internets:

    10.0.0.0 - 10.255.255.255 (10/8 prefix)
    172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
    192.168.0.0 - 192.168.255.255 (192.168/16 prefix)


    And this is not always true "My ISP assigns me, say, an IP address of 80.123.45.65. That address is specified in the NIC interface in the Router to the outside world, Any device on the Internet wishing to communicate with me via IP will use that address. I had always assumed that was a "Public IP Address"

    THE INTERNET

    my pc --- my router --- ISP router --- ISP router --- ... ... ... --- Yahoo.com


    >> Start Trace
    Sunday, January 06, 2008 6:30:50 AM
    www.yahoo.com (209.191.93.52)
    www.yahoo-ht3.akadns.net
    1 10.0.0.75 3
    2 216.106.17.1 7
    3 216.106.6.84 19
    4 216.106.6.82 19
    5 64.214.143.125 19
    6 67.17.108.10 32
    7 208.50.13.110 39
    8 216.115.104.111 40
    9 68.142.193.11 37
    10 209.191.93.52 36
    End Pass # 1 @ 06:30:52

    1 10.0.0.75 3
    2 216.106.17.1 7
    3 216.106.6.84 31
    4 216.106.6.82 31
    5 64.214.143.125 127
    6 67.17.108.10 32
    7 208.50.13.110 35
    !! 8 216.115.104.107 46
    !! 9 68.142.193.5 43
    10 209.191.93.52 36
    End Pass # 2 @ 06:30:55

    >> End Trace Sunday, January 06, 2008 6:30:55 AM
    www.yahoo.com (209.191.93.52)
    Trace Route Summary
    Hop Avg RTT IP Address(es)
    1 3 10.0.0.75
    2 7 216.106.17.1
    3 25 216.106.6.84
    4 25 216.106.6.82
    5 73 64.214.143.125
    6 32 67.17.108.10
    7 37 208.50.13.110
    8 43 216.115.104.111 216.115.104.107
    9 40 68.142.193.11 68.142.193.5
    10 36 209.191.93.52

    Hop Host Name(s)
    1 10.0.0.75
    2 216.106.17.1
    3 ol1.kcmo.socket.net
    4 gw2.kcmo.socket.net
    5 64.214.143.125
    6 ge8-1-10G.ar2.DAL2.gblx.net
    7 yahoo-1.ar1.DAL2.gblx.net
    8 ge-1-1-0-p111.msr2.mud.yahoo.com
    ge-1-1-0-p101.msr1.mud.yahoo.com
    9 te-9-1.bas-c2.mud.yahoo.com
    te-8-1.bas-c1.mud.yahoo.com
    10 f1.www.vip.mud.yahoo.com

    >> Ready
    Last edited by dbasnett; Jan 6th, 2008 at 07:32 AM.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  14. #14
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    If you have a public IP NEVER post it anywhere!
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  15. #15
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    Sorry, I've missed the point somewhere. You're quoting RFC1918 Private Address space - which I have no argument with.

    Basically, what I'm saying is that the local Router knows the External IP Address and it's possible (and desirable) to obtain it from there if required.

    I or anyone else, could create a web site which purports to tell you your IP address, and just tell lies. Might be far fetched, but the only 'real' source of reliable information is the device you have control over, ie your router.

  16. #16
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    In the original post "...how do i find the public ip". Seems clear to me.

    1. Your home router, and any number of the ISP's routers, may or may not have "public" IP addresses.

    2. In all those cases(see 1), if it is public, it may or may not be a real "public" address. How many home systems have I seen with "public" IP's? itsa big number

    3. The only time you will know what your real "public" IP address is, is to receive and examine a packet that has traversed a Private / Public boundary. And there is no guarantee that it will be the same in the next ms.

    I was trying to use Public / Private so we would all be on the same page. If External refers to ANY IP address then I agree with this: "Basically, what I'm saying is that the local Router knows the External IP Address"
    If External means Public then it is an incorrect statement.

    OK, this is true: "I or anyone else, could create a web site which purports to tell you your IP address, and just tell lies. Might be far fetched, but the only 'real' source of reliable information is the device you have control over, ie your router."

    Unfortunately the ip address of the router may be 192.168.1.1, good luck passing that to the internet.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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

    Re: finding the public IP

    The real question is "What do you want it for?"

    Your program can't connect to itself this way (well yeah, but that's sort of pointless). It can't "tell" another program on another computer (how did your program learn the other guy's public IP address?).

    What, is it going to display it to you so you can manually view it and then type it in and send it to another guy via email, fax, IM, etc. just so he can type it in at his end?

    Sheesh.

    Why not just use a dynamic DNS service and be done with it? True, you may need to run an "updater" application to "ping" the DNS server and thus tell it your current IP address periodically. That's just life in the big city though.

    That or find a peer name resolution service to register with, and have to send those update pings anyway.


    The big downside of NAT is that it breaks the peer to peer Internet. IPv6 proponents use this argument to push their agenda, but I doubt that will ever get anywhere. It's been years in the offing and still no results. The Internet mega-corporations want us locked into a "broadcast like" model of the Internet anyway, so they can control content and push advertising in your face. Unlike TV though, you can order their junk directly from your PC - so they love it.

    Ginsu knives anyone? Maybe some "male enhancement?" How about the latest Visual Studio? Some "dynamic talking characters" for your web site?

  18. #18
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    I hadn't mentioned Dynamic DNS but it will sure allow you to store a public IP for the world to see.
    But they may be fabricating the IP address so beware.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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

    Re: finding the public IP

    Well if you're that paranoid you might have to start stringing your own cables.

  20. #20
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: finding the public IP

    Quote Originally Posted by dbasnett
    Unfortunately the ip address of the router may be 192.168.1.1, good luck passing that to the internet.
    I am still confused about the use of the word "Public". The address as seen by my machine when looking at the Router may well be 192.168.1.1 but the adddress looking from the Internet towards the router, and vice versa, may be 80.123.45.67

    All I'm saying is that you can interrogate the Router to find that address (80.123.45.67) and that is more reliable than 'asking' an external web site.

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

    Re: finding the public IP

    No, because the ISP may have another NAT router beyond yours. In such cases asking your local router has 0 reliability.

    I think that was his point.

  22. #22
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: finding the public IP

    Quote Originally Posted by Doogle
    I am still confused about the use of the word "Public". The address as seen by my machine when looking at the Router may well be 192.168.1.1 but the adddress looking from the Internet towards the router, and vice versa, may be 80.123.45.67

    All I'm saying is that you can interrogate the Router to find that address (80.123.45.67) and that is more reliable than 'asking' an external web site.
    Maybe YOU can, but your answer has a limited audience.

    About Public / Private aka Routable / non-routable
    From RFC1918
    Category 1: hosts that do not require access to hosts in other
    enterprises or the Internet at large; hosts within
    this category may use IP addresses that are
    unambiguous within an enterprise, but may be
    ambiguous between enterprises.

    Category 2: hosts that need access to a limited set of outside
    services (e.g., E-mail, FTP, netnews, remote login)
    which can be handled by mediating gateways (e.g.,
    application layer gateways). For many hosts in this
    category an unrestricted external access (provided
    via IP connectivity) may be unnecessary and even
    undesirable for privacy/security reasons. Just like
    hosts within the first category, such hosts may use
    IP addresses that are unambiguous within an
    enterprise, but may be ambiguous between
    enterprises.

    Category 3: hosts that need network layer access outside the
    enterprise (provided via IP connectivity); hosts in
    the last category require IP addresses that are
    globally unambiguous.

    We will refer to the hosts in the first and second categories as
    "private". We will refer to the hosts in the third category as
    "public".
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

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