MartyConnelly
martyconnelly at shaw.ca
Thu Mar 22 14:26:59 CDT 2007
Here is an alternate method of getting IP address.
Public Sub GrabIPAddress()
'retrieves users IP address from website dyndns.org
' looking back at machine from outside firewall
' uses XPath to parse returned html page
'website has been up 5 years.
'page returned is html text
Dim objHTTP As New MSXML2.XMLHTTP
'need to set reference to xml 4.0 or late bind
Dim strWebPage As String
On Error Resume Next
'Retrieve Web Page URL
strWebPage = "http://checkip.dyndns.org/"
objHTTP.Open "POST", strWebPage, False
objHTTP.setRequestHeader "Content-Type", _
"application/x-www-form-urlencoded "
objHTTP.send
'check for http errors
If Err.Number Or objHTTP.status <> "200" Then
'errors include 501 500 and (404 page not found)
MsgBox Err.Number & Err.Description
MsgBox objHTTP.status
MsgBox "Cannot retrieve page!"
Debug.Print Err.Number & Err.Description
Exit Sub
End If
' look at the response
Debug.Print objHTTP.getAllResponseHeaders
Debug.Print objHTTP.statusText
Debug.Print objHTTP.responseText
'Pass Response back from Server
Debug.Print objHTTP.responseText
'Now parse the returned xml for specific nodes via XPath
Dim xmlDoc As New MSXML2.DOMDocument
Dim objNodeList As IXMLDOMNodeList
Dim objNode As MSXML2.IXMLDOMNode
xmlDoc.async = False
xmlDoc.loadXML objHTTP.responseText
'error check dom load here and use XPath method for node selection
xmlDoc.setProperty "SelectionLanguage", "XPath"
Set objNodeList = xmlDoc.documentElement.selectNodes("//body")
Debug.Print objNodeList.length
For Each objNode In objNodeList
Debug.Print objNode.Text
Next
End Sub
>
>
>>>>jwcolby at colbyconsulting.com 22-03-2007 14:59 >>>
>>>>
>>>>
>Is there VBA code out there to obtain the IP address of the current
>workstation? I found code that goes through the registry, and it ALMOST
>works, in fact it does work in many instances but...
>
>John W. Colby
>Colby Consulting
>www.ColbyConsulting.com
>
>
>
--
Marty Connelly
Victoria, B.C.
Canada