'****************************************************
'		Script Witten by Larry Heintz
'		March 2005 www.windowsadminscripts.com
' This script will query all IP Addresses on all NIC
' cards that have TCP/IP enabled on it on the computer
' you enter in as the /computer argument.
'
' Script Usage:
' cscript getips.vbs /computer:[Computer Name]
'****************************************************
'On Error Resume Next
' Dims stuff
Dim objStdOut,args
' Set Stuff
Set objStdOut = Wscript.stdOut
Set args = Wscript.Arguments.Named
computer = args.item("computer")

if wscript.arguments.count = 1 then
	wscript.echo "Computer: " & ucase(computer)
	set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computer & "\root\cimv2").ExecQuery _
		("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE")
		for each IPConfig in IPConfigSet
			''/// Gets All the IP Address
			if Not IsNull(IPConfig.IPAddress) then
				for i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
					wscript.echo "IP Address: " & IPConfig.IPAddress(i)
				next
			end if
			''/// Gets the Default Gateway IP
			if Not IsNull(IPConfig.DefaultIPGateway) then
				for i=LBound(IPConfig.DefaultIPGateway) to UBound(IPConfig.DefaultIPGateway)
					wscript.echo "Default IP Gateway(s): " & IPConfig.DefaultIPGateway(i)
				next
			end if
			''/// Gets the DNSServerSearchOrder of the card
			if Not IsNull(IPConfig.DNSServerSearchOrder) then
				for i=LBound(IPConfig.DNSServerSearchOrder) to UBound(IPConfig.DNSServerSearchOrder)
					wscript.echo "DNS Servers: " & IPConfig.DNSServerSearchOrder(i)
				next
			end if
			''/// Gets the DNSHostName  of the card
			if Not IsNull(IPConfig.DNSHostName) then
				wscript.echo "DNSHostName: " & IPConfig.DNSHostName
			end if
			''/// Gets the MAC Address of the card
			if Not IsNull(IPConfig.MACAddress) then
				wscript.echo "MAC Address: " & IPConfig.MACAddress
			end if
		next
	set IPConfigSet = nothing
else
	objStdOut.Write "Usage: cscript getips.vbs /computer:[Computer Name]"
	objStdOut.close
	wscript.quit
end if

if err.number <> 0 then
	wscript.echo "There was an issue connecting to the computer. Please check the computer name."
end if
