PDA

Click to See Complete Forum and Search --> : Get Internet IP Address.


dandono
Dec 27th, 2005, 04:42 AM
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
Function get_ip()
'Fetch external ip function
'- checks checkip.dyndns.org for computers ip adress
Dim ReturnedHTML As String, sIp As Long, sStop As Long

ReturnedHTML = ReturnHTML("http://checkip.dyndns.org/")

sIp = InStr(ReturnedHTML, "Address: ") + 9

If InStr(sIp, ReturnedHTML, ",") > 0 Then
sStop = InStr(sIp, ReturnedHTML, ",")
Else
sStop = InStr(sIp, ReturnedHTML, "<")
End If

If sStop > 0 Then 'Fetched ip
get_ip = Mid(ReturnedHTML, sIp, sStop - sIp)
Else 'Error occured
get_ip = "error"
End If
End Function

Private Function ReturnHTML(URL)
'Return HTML function
'- retrieves HTML for the given url
Dim objXMLHTTP, objRS, HTML
Set objXMLHTTP = CreateObject("Microsoft.XMLHTTP")
objXMLHTTP.Open "GET", URL, False
objXMLHTTP.Send
HTML = objXMLHTTP.responseBody
Set objRS = CreateObject("ADODB.Recordset")
objRS.Fields.Append "txt", 200, 45000, &H80
objRS.Open
objRS.AddNew
objRS.Fields("txt").AppendChunk HTML
ReturnHTML = objRS("txt").Value
objRS.Close
Set objXMLHTTP = Nothing
Set objRS = Nothing
End Function

The code can be used like this

me.caption = Get_IP
'or
text1.text = Get_IP

i did not write this code and i do not remember who wrote it.

Coreybellamy
Mar 28th, 2007, 08:31 PM
Nice thanks for posting

sessi4ml
Mar 30th, 2007, 02:06 PM
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.