Get Local/Gateway IP Addresses
Two days ago, on Adobe’s InDesign Scripting forum I had found question about retrieving Router IP address. Post is based on MacOS/Applescript, and I decided to find solution for Windows
It’s combination of VBscript and JavaScript. Let’s get started.
In VBscript we create WMIService object, and query Win32_NetworkAdapterConfiguration. More info can be found on Microsoft MSDN. We are going to call VBscript with Javascript and pass values back to Javascript. First, copy this script and save it in our scripts folder with following name: GetMyIP.vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
If Not (IPConfig.IPAddress(i)="0.0.0.0") Then
IPAddr = IPAddr + IPConfig.IPAddress(i) + vbNewLine
End If
Next
End If
If Not IsNull(IPConfig.DefaultIPGateway) Then
For i=LBound(IPConfig.DefaultIPGateway) to UBound(IPConfig.DefaultIPGateway)
If Not (IPConfig.DefaultIPGateway(i)="0.0.0.0") Then
IPGate = IPGate + IPConfig.DefaultIPGateway(i) + vbNewLine
End If
Next
End If
Next
app.scriptArgs.SetValue "myIP", IPAddr
app.scriptArgs.SetValue "myGATE", IPGate
As you can see, last two lines are passing values back to Javascript. It’s important to match argument name in both scripts, or we will get empty value.
Now, let’s open new Javascript file, and paste this script:
app.doScript(File(app.activeScript.path+'/GetMyIP.vbs'), ScriptLanguage.visualBasic);
var myIP = app.scriptArgs.getValue("myIP");
var myGateway = app.scriptArgs.getValue("myGATE");
So, we call doScript and point it to file we created earlier, and important thing is to set script language (ScriptLanguage.visualBasic). After command is executed, we can read scriptArgs, and if everything went ok, we got our IP addresses. I hope it will work for you! It would be nice to receive some feedback
This script is tested on InDesign CS4/CS5 on Windows 7, and I will test it on CS5/WinXP later.
Have fun!
IndiSnip on Twitter!
IndiSnip on Facebook!
Contact IndiSnip by e-mail!

wow
Simple cool and great!
Great job don tomaxxi…..Thanks