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.
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.