Skip navigation

How can I use a script to generate a list of all IP addresses on a machine?

A. The following script will write to screen each IP address on a client.

Option Explicit 
Dim IPConfigSet, IPConfig, i

set IPConfigSet = GetObject("winmgmts:\{impersonationLevel=impersonate\}!root\cimv2").ExecQuery("SELECT IPAddress, DefaultIPGateway FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
for each IPConfig in IPConfigSet
  if Not IsNull(IPConfig.IPAddress) then 
    wscript.echo IPConfig.IPAddress(i)
  end if

The output below shows a sample execution.

D:\temp>cscript listip.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.