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") "POST", "", False

'-- --'
xmlhttp.setRequestHeader "SOAPAction", "urn:schemas-upnp-org:service:WANIPConnection:1#GetExternalIPAddress"

Dim theRequest 'As String

'-- (SOAP 1.1) --'
theRequest = "<?xml version=""1.0""?>" & VbCrlf & "<SOAP-ENV:Envelope xmlns:SOAP-ENV="""" SOAP-ENV:encodingStyle=""""%lt;>SOAP-ENV:Body><m:GetExternalIPAddress xmlns:m=""urn:schemas-upnp-org:service:WANIPConnection:1""/></SOAP-ENV:Body></SOAP-ENV:Envelope>"

' -- (SOAP 1.2 Part 1) --'
'theRequest = "<s:Envelope" & vbCrLf
'theRequest = theRequest & "    xmlns:s=""""" & vbCrLf
'theRequest = theRequest & "    s:encodingStyle="""">" & 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

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




Remember Me           E-mail me replies

Content (HTML not allowed)