Results 1 to 4 of 4

Thread: Get Internet IP Address.

  1. #1

    Thread Starter
    Hyperactive Member dandono's Avatar
    Join Date
    Aug 2004
    Location
    Cornwall, UK
    Posts
    485

    Get Internet IP Address.

    Hi, I found this code on one of my computers and thought it might be usefull to someone. I did not write this code but i cannot remember who did. Please post if you are the writer of this code.

    Put this code in a form
    VB Code:
    1. Function get_ip()
    2. 'Fetch external ip function
    3. '- checks checkip.dyndns.org for computers ip adress
    4.     Dim ReturnedHTML As String, sIp As Long, sStop As Long
    5.  
    6.     ReturnedHTML = ReturnHTML("http://checkip.dyndns.org/")
    7.  
    8.     sIp = InStr(ReturnedHTML, "Address: ") + 9
    9.  
    10.     If InStr(sIp, ReturnedHTML, ",") > 0 Then
    11.         sStop = InStr(sIp, ReturnedHTML, ",")
    12.     Else
    13.         sStop = InStr(sIp, ReturnedHTML, "<")
    14.     End If
    15.  
    16.     If sStop > 0 Then 'Fetched ip
    17.         get_ip = Mid(ReturnedHTML, sIp, sStop - sIp)
    18.     Else 'Error occured
    19.         get_ip = "error"
    20.     End If
    21. End Function
    22.  
    23. Private Function ReturnHTML(URL)
    24. 'Return HTML function
    25. '- retrieves HTML for the given url
    26.     Dim objXMLHTTP, objRS, HTML
    27.     Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
    28.     objXMLHTTP.Open "GET", URL, False
    29.     objXMLHTTP.Send
    30.     HTML = objXMLHTTP.responseBody
    31.     Set objRS = CreateObject("ADODB.Recordset")
    32.     objRS.Fields.Append "txt", 200, 45000, &H80
    33.     objRS.Open
    34.     objRS.AddNew
    35.     objRS.Fields("txt").AppendChunk HTML
    36.     ReturnHTML = objRS("txt").Value
    37.     objRS.Close
    38.     Set objXMLHTTP = Nothing
    39.     Set objRS = Nothing
    40. End Function

    The code can be used like this
    VB Code:
    1. me.caption = Get_IP
    2. 'or
    3. text1.text = Get_IP
    i did not write this code and i do not remember who wrote it.
    If there is only one perfect person in the universe, does that make them imperfect?

  2. #2
    New Member
    Join Date
    Mar 2007
    Posts
    5

    Re: Get Internet IP Address.

    Nice thanks for posting

  3. #3
    Fanatic Member sessi4ml's Avatar
    Join Date
    Nov 2006
    Location
    Near San Francisco
    Posts
    958

    Re: Get Internet IP Address.

    Dandono, could you post the IP code again using 'code' tags.

    The 'vbcode' tags will not allow to copy/paste....
    Thanks
    I want to add your code to the MAC code.

  4. #4
    Addicted Member
    Join Date
    Feb 2004
    Posts
    153

    Re: Get Internet IP Address.

    QUESTION:

    This is a great code-bit. Seems to work flawlessly to get IP address of any connection.

    I got this strange result from a remote customer. What does it mean if my parsed answer = "192.168.0.XXX", rather than the Publlic IP address?

    Why or what conditions this method would give local machine ip address?
    Last edited by Jimboat; Jul 23rd, 2021 at 08:22 AM.
    /Jimboat

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