Results 1 to 19 of 19

Thread: What is my IP address?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2007
    Posts
    788

    What is my IP address?

    Dear Friends,

    How to get the IP address of my computer when I am connected to the internet?

    Please let me know the vb6 code to get the IP address.


    Regards,

    vblearner6

  2. #2
    Lively Member
    Join Date
    Mar 2007
    Posts
    98

    Re: What is my IP address?

    Dude u really need to look this **** up before asking such basic questions that have been covered so many times. Head on over to PSC, there u will find so many different variations of that sort of **** its like a network programmers wet dream.

  3. #3
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: What is my IP address?

    SmackAHobo i suggest being more helpful than that.

    vb Code:
    1. Private Sub Command1_Click()
    2. MsgBox Winsock1.LocalIP
    3. End Sub


  4. #4
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: What is my IP address?

    Yours, on your network; you can find with a simple command promp and typing "ipconfig"

    (assuming you have a router) If you need to find the IP of your gateway, log into your router:

    typically: http://192.168.1.1
    and if you use a linksys, it's admin for the user and admin for the password.

    And look up you specs in there.

  5. #5
    Member
    Join Date
    Feb 2007
    Location
    Lame, Illinois
    Posts
    43

    Re: What is my IP address?

    Or you can google "Whats my ip"

    =P

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

    Re: What is my IP address?

    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


  7. #7
    Lively Member
    Join Date
    Mar 2007
    Posts
    98

    Re: What is my IP address?

    Hell Lord, he was asking what his internet IP is, not his local ip.

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

    Re: What is my IP address?

    The .LocalIP will work if they are not behind a router/on a network.

    Otherwise, you'll have to use a remote server like iPrank posted.

    Or write your own PHP script and put it on a server that supports PHP. The simplest way would be:

    PHP Code:
    <?php
    echo $_SERVER['REMOTE_ADDR'];
    ?>

  9. #9
    Interweb adm/o/distrator Paul M's Avatar
    Join Date
    Nov 2006
    Location
    Australia, Melbourne
    Posts
    2,306

    Re: What is my IP address?

    Quote Originally Posted by SmackAHobo
    Hell Lord, he was asking what his internet IP is, not his local ip.

    He asked for his IP when an internet connection is made. And that code will get him his localIP which is it. If there is no connection it will give him 127.0.0.1 obviously. And if he has established an internet connection then it will give him his IP

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

    Re: What is my IP address?

    Quote Originally Posted by Hell-Lord
    He asked for his IP when an internet connection is made. And that code will get him his localIP which is it. If there is no connection it will give him 127.0.0.1 obviously. And if he has established an internet connection then it will give him his IP
    When on a network LocalIP is not the same as Internet IP. Most people use routers these days, so will need to contact an external service such as iPrank and DigiRev mentioned
    Chris

  11. #11
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: What is my IP address?

    No, no you don't need to use an external site. You can and thats fine and dandy, but you can get the information from your router on what your gateway's IP is. If you don't have a static one, it'll change 3 or 4 times a week, but you can still get it without assistance.

    Not to mention, some ISPs will proxy; meaning - you can't find your own IP address through those kinds of sites. You make a request and then they "peel the packet" and remake the request for you. It helps cut down on upload traffic and also gives them a quick, single spot way of determining if that site is attempting to do something malicious in response to your request. ISPs don't promise protection (liability reasons), but they do protect to some degree.

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

    Re: What is my IP address?

    Quote Originally Posted by sevenhalo
    No, no you don't need to use an external site. You can and thats fine and dandy, but you can get the information from your router on what your gateway's IP is. If you don't have a static one, it'll change 3 or 4 times a week, but you can still get it without assistance.

    Not to mention, some ISPs will proxy; meaning - you can't find your own IP address through those kinds of sites. You make a request and then they "peel the packet" and remake the request for you. It helps cut down on upload traffic and also gives them a quick, single spot way of determining if that site is attempting to do something malicious in response to your request. ISPs don't promise protection (liability reasons), but they do protect to some degree.
    It's easier to get it from a site such as provided than to try and programatically get it from the router
    Chris

  13. #13
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: What is my IP address?

    Quote Originally Posted by the182guy
    It's easier to get it from a site such as provided than to try and programatically get it from the router
    What part of what I said lead you to beleive I was suggesting to get it programatically?

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

    Re: What is my IP address?

    Quote Originally Posted by sevenhalo
    What part of what I said lead you to beleive I was suggesting to get it programatically?
    The thread starter wanted to get it programatically.

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

    Re: What is my IP address?

    Here is a demo that does it programmatically both ways. I hope it doesn't drive anyone batty trying to make sense of the code.

    Short answer: an external web site is much easier, much less code. Though you need to hard-code an external URL and tailored parsing logic you only need to do it once.

    Asking the NAT router is not only a lot of work but you need a URL (or at least a page) hard coded along with parsing logic for every different router. It's more work because you have to discover the NAT router to ask it... unless you do hard-code the entire URL.

    Of course the URLs and parsing "bracket" strings can be parameterized fairly simply. The demo shows this clearly. Note that the "ask your NAT" part of the demo won't work unless you insert values that fit your own router into the demo form. Otherwise it will return the Local IP marked as "questionable."
    Last edited by dilettante; May 16th, 2007 at 05:25 PM.

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

    Re: What is my IP address?

    Quote Originally Posted by dilettante
    Here is a demo that does it programmatically both ways. I hope it doesn't drive anyone batty trying to make sense of the code.

    Short answer: an external web site is much easier, much less code. Though you need to hard-code an external URL and tailored parsing logic you only need to do it once.

    Asking the NAT router is not only a lot of work but you need a URL (or at least a page) hard coded along with parsing logic for every different router. It's more work because you have to discover the NAT router to ask it... unless you do hard-code the entire URL.

    Of course the URLs and parsing "bracket" strings can be parameterized fairly simply. The demo shows this clearly. Note that the "ask your NAT" part of the demo won't work unless you insert values that fit your own router into the demo form. Otherwise it will return the Local IP marked as "questionable."
    Exactly, it's completely insane to try and get it from the router's control panel when every manufacturer is different, and to make it even harder, a lot of them require authentication before giving you access to the IP.

    You can do it in one line with the Inet control, a few lines with winsock, and a lot more with the winsock API.
    Chris

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

    Re: What is my IP address?

    I tried fussing with my router to see if I could make a version more "portable" (i.e. handle any UPnP router) but I never got very far. The UPnP approach wasn't very practical, and at best required several requests of the router via HTTP.

    AS far as I know most home routers can return the required info without a logon though, via an HTML status page. Usually this is the default page.

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

    Re: What is my IP address?

    Well the most professional way that will support all routers is to have a server-side script running on a webhost, have the script require a password so nobody else can use it. The script will return the IP when executed and authenticated.

    You can get a basic PHP host for about £3 per month.

    I wouldn't use whatismyip.org in a professional or commercial app because its obviously an external party and they could be doing anything with the IP's they return.
    Chris

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

    Re: What is my IP address?

    Quote Originally Posted by the182guy
    Well the most professional way that will support all routers is to have a server-side script running on a webhost, have the script require a password so nobody else can use it. The script will return the IP when executed and authenticated.

    You can get a basic PHP host for about £3 per month.

    I wouldn't use whatismyip.org in a professional or commercial app because its obviously an external party and they could be doing anything with the IP's they return.
    Yea I'd definitely not rely on any other sites for getting an IP address when it comes to professional apps. If you're selling a commercial app, then you should put the script on your website and use that.

    Then you just need to make sure your site doesn't go down.

    To save bandwidth/prevent everyone from using your script to get their IPs you can also compress the IP into 4 bytes.

    Chr$(Octect1) & Chr$(Octect2) & Chr$(Octect3) & Chr$(Octect4)

    Then just ASC the compressed 4 bytes back into an IP

    Asc(C1) & "." & Asc(C2) etc...

    This is how I did mine: www.dannydotguitar.com/ip.php

    Here's the source to the PHP script, not sure if anyone will find it useful, but whatever.

    PHP Code:
    <?php
      $ip 
    $_SERVER['REMOTE_ADDR'];
      
    $oct explode('.'$ip);
      
    $pack_ip chr($oct[0]) . chr($oct[1]) . chr($oct[2]) . chr($oct[3]);
      
      echo 
    $pack_ip;
    ?>
    Oh, and the VB code to 'unpack' the IP.

    vb Code:
    1. Private Sub Command1_Click()
    2.     Dim strData As String, strIP As String
    3.    
    4.     strData = Inet1.OpenURL("http://www.dannydotguitar.com/ip.php")
    5.    
    6.     If Len(strData) = 4 Then
    7.         strIP = Asc(Left$(strData, 1)) & "." & _
    8.                 Asc(Mid$(strData, 2, 1)) & "." & _
    9.                 Asc(Mid$(strData, 3, 1)) & "." & _
    10.                 Asc(Right$(strData, 1))
    11.     End If
    12. End Sub
    Last edited by DigiRev; May 17th, 2007 at 03:57 PM.

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