Home > HOT Posts!, InDesign Scripts > Get Local/Gateway IP Addresses

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)="") Then
		    IPAddr = IPAddr + IPConfig.IPAddress(i) + vbNewLine
            	End If
    End If
    If Not IsNull(IPConfig.DefaultIPGateway) Then 
        For i=LBound(IPConfig.DefaultIPGateway) to UBound(IPConfig.DefaultIPGateway)
                If Not (IPConfig.DefaultIPGateway(i)="") Then
		    IPGate = IPGate + IPConfig.DefaultIPGateway(i) + vbNewLine
            	End If
    End If

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!

  1. sinisa
    July 30, 2010 at 13:52


  2. Anil Yadav
    August 3, 2010 at 06:46

    Simple cool and great!

    Great job don tomaxxi…..Thanks

  1. July 31, 2010 at 10:40

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: