Comments For Entry #636

UPnP, IP Addresses and VBScript / VisualBasic(Comments RSS)

I couldn't find anywhere on the internet that already offered this so I had to make a makeshift solution myself using network sniffing software and a bit of research.

Do you want to use VBScript to ask a UPnP capable router what its current external IP address is?

Open up notepad and save this as "WhatIsMyIP.vbs"

Option Explicit

Dim xmlhttp 'As MSXML2.ServerXMLHTTP
Set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")

xmlhttp.open "POST", "http://192.168.1.1:2869/WANIPConnCtrlUrl", False

'-- http://www.oreillynet.com/xml/blog/2002/11/unraveling_the_mystery_of_soap.html --'
xmlhttp.setRequestHeader "SOAPAction", "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"

Dim theRequest 'As String

'-- http://www.w3.org/TR/2000/NOTE-SOAP-20000508/ (SOAP 1.1) --'
theRequest = "<?xml version=""1.0""?>" & VbCrlf & "<SOAP-ENV:Envelope xmlns:SOAP-ENV=""http://schemas.xmlsoap.org/soap/envelope/"" SOAP-ENV:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/""%lt;>SOAP-ENV:Body><m:GetExternalIPAddress xmlns:m=""urn:schemas-upnp-org:service:WANIPConnection:1""/></SOAP-ENV:Body></SOAP-ENV:Envelope>"

' -- http://www.w3.org/TR/2003/REC-soap12-part1-20030624/#soapencattr (SOAP 1.2 Part 1) --'
'theRequest = "<s:Envelope" & vbCrLf
'theRequest = theRequest & "    xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""" & vbCrLf
'theRequest = theRequest & "    s:encodingStyle=""http://schemas.xmlsoap.org/soap/encoding/"">" & vbCrLf
'theRequest = theRequest & "  <s:Body>" & vbCrLf
'theRequest = theRequest & "    <u:GetExternalIPAddress xmlns:u=""urn:schemas-upnp-org:service:WANIPConnection:1"">" & vbCrLf
'theRequest = theRequest & "    </u:GetExternalIPAddress>" & vbCrLf
'theRequest = theRequest & "  </s:Body>" & vbCrLf
'theRequest = theRequest & "</s:Envelope>" & vbCrLf
  
xmlhttp.send(theRequest)

Dim xmlDoc 'As MSXML2.DOMDocument30
Set xmlDoc = xmlhttp.responseXML
  MsgBox (xmlDoc.Text)
Set xmlDoc = Nothing

Set xmlhttp = Nothing


Notes :

  • I haven't actually set this script to properly interpret the response

  • This code is based on the Linksys WRT54GS (I imagine the WRT54G and WRT54GL will handle it just as well).

  • It should work on all Linksys routers but I haven't any other Linksys equipment to hand to test this...

  • I am assuming your router's IP address is 192.168.1.1 (The default)



Either way this is a pretty neat script that you can go on to use in other Visual Basic or VBScript.. I for instance originally had my server e-mail me of any IP address changes of the main network adapater.. but since installing the router this somewhat messed it up.. thankfully this little script now provides a suitable work around.

I'm sure others will have a use for this too.

Keywords : UPnP, IP Address, Visual Basic, VBScript, SOAP, External, Address, Router, Linksys, WRT54, WRT54GS, WRT54GL

Pingbacks For Entry #636

Add New Comment

Name

E-mail

Homepage

Remember Me           E-mail me replies

Content (HTML not allowed)