'****************************************************
'		Script Witten by Larry Heintz
'		March 2006 www.windowsadminscripts.com
' This script will retrieve various settings on each
' NIC Card on a computer. It will retrieve IP's,MAC
' Address,Gateways,Last Reset Time,DHCP Info,IPX
' Info and WINS Info as well as various other info.
'
' Script Usage: cscript nic.vbs /computer:[computername]
'****************************************************
Dim args
Set args = Wscript.Arguments.Named
computername = args.Item("computer")

if wscript.arguments.count = 0 then
	wscript.echo "Script Usage: nic.vbs /computer:[computername]"
elseif args.exists("computer") then
	if computername = "" then
		computername = "."
	else
		computername = computername
	end if
	Call getStuff(computername)
end if

Function getStuff(computername)
On Error Resume Next
Dim NICConfigSet,nicobj
set NICConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computername & "\root\cimv2").ExecQuery _
		("SELECT * FROM Win32_NetworkAdapter Where AdapterType = 'Ethernet 802.3'")
if not (errorChecking (computername)) then
	for each nicobj in NICConfigSet
		wscript.echo nicobj.Description & " Adapter Information" & VbCrLF
		wscript.echo "Adapter ID: " & nicobj.Index
		wscript.echo "Adapter Type: " & nicobj.AdapterType
		wscript.echo "Adapter Name: " & nicobj.Description
		wscript.echo "Adapter Manufacturer: " & nicobj.Manufacturer
		wscript.echo "Adapter Connection Name: " & 	getNetConnectionID(nicobj.Index,computername)
		wscript.echo "Adapter PNP Device ID: " & nicobj.PNPDeviceID
		wscript.echo "Adapter Last Reset: " & convertTime(nicobj.TimeOfLastReset)
		Call getNICExtras(nicobj.Index,computername)
		wscript.echo "==================================================="
	next
end if
set NICConfigSet = nothing
End Function

Function getNICExtras(index,computername)
Dim IPConfigSet,ObjIP
set IPConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computername & "\root\cimv2").ExecQuery _
		("SELECT * FROM Win32_NetworkAdapterConfiguration Where Index = " & index & "")
	for each ObjIP in IPConfigSet
		if Not IsNull(ObjIP.DefaultIPGateway) then
			for i=LBound(ObjIP.DefaultIPGateway) to UBound(ObjIP.DefaultIPGateway)
				wscript.echo "Adapter Default IP Gateway(s): " & ObjIP.DefaultIPGateway(i)
			next
		end if
		if Not IsNull(ObjIP.IPAddress) then
			for i=LBound(ObjIP.IPAddress) to UBound(ObjIP.IPAddress)
				wscript.echo "Adapter IP Address: " & ObjIP.IPAddress(i) & "," & ObjIP.IPSubNet(i)
			next
		end if
		wscript.echo "Adapter DHCP Enabled: " & ObjIP.DHCPEnabled
		if ObjIP.DHCPEnabled = True then
			wscript.echo "Adapter DHCP Server IP: " & ObjIP.DHCPServer
			wscript.echo "Adapter DHCP Lease Obtained: " & convertTime(ObjIP.DHCPLeaseObtained)
			wscript.echo "Adapter DHCP Lease Expires: " & convertTime(ObjIP.DHCPLeaseExpires)
		end if
		wscript.echo "Adapter DNS Domain: " & ObjIP.DNSDomain
		if Not IsNull(ObjIP.DNSDomainSuffixSearchOrder) then
			for i=LBound(ObjIP.DNSDomainSuffixSearchOrder) to UBound(ObjIP.DNSDomainSuffixSearchOrder)
				wscript.echo "Adapter DNS Domain Suffix Search Order: " & ObjIP.DNSDomainSuffixSearchOrder(i)
			next
		end if
		if Not IsNull(ObjIP.DNSServerSearchOrder) then
			for i=LBound(ObjIP.DNSServerSearchOrder) to UBound(ObjIP.DNSServerSearchOrder)
				wscript.echo "Adapter DNS Domain Search Order: " & ObjIP.DNSServerSearchOrder(i)
			next
		end if
		wscript.echo "Adapter MAC Address: " & ObjIP.MACAddress
		Select Case ObjIP.TcpipNetbiosOptions
			Case 0
				wscript.echo "Adapter Tcpip Netbios Options: Use Netbios setting from DHCP Server"
			Case 1
				wscript.echo "Adapter Tcpip Netbios Options: Enable Netbios"
			Case 2
				wscript.echo "Adapter Tcpip Netbios Options: Disable Netbios"
		End Select
		wscript.echo "Adapter IP Filter Security Enabled: " & ObjIP.IPFilterSecurityEnabled
		wscript.echo "Adapter Database Path: " & ObjIP.DatabasePath
		wscript.echo "Adapter IGMP Level: " & ObjIP.IGMPLevel
		if ObjIP.WINSEnableLMHostsLookup = True then
			wscript.echo "Adapter WINS Enable LMHosts Lookup: True"
			wscript.echo "Adapter WINS Scope ID: " & ObjIP.WINSScopeID
			wscript.echo "Adapter WINS Host Lookup File: " & ObjIP.WINSHostLookupFile
			wscript.echo "Adapter WINS Primary Server: " & ObjIP.WINSPrimaryServer
			wscript.echo "Adapter WINS Secondary Server: " & ObjIP.WINSSecondaryServer
		end if
		if ObjIP.IPXEnabled = True then
			wscript.echo "Adapter IPX IP Address:" & ObjIP.IPXAddress
			Select Case ObjIP.IPXFrameType(0)
				Case 0
					wscript.echo "Adapter IPX Frame Type: Ethernet II"
				Case 1
					wscript.echo "Adapter IPX Frame Type: Ethernet 802.3"
				Case 2
					wscript.echo "Adapter IPX Frame Type: Ethernet 802.2"
				Case 3
					wscript.echo "Adapter IPX Frame Type: Ethernet SNAP"
				Case 255
					wscript.echo "Adapter IPX Frame Type: AUTO"
			End Select
			wscript.echo "Adapter IPX Media Type:" & ObjIP.IPXMediaType
			for i=LBound(ObjIP.IPXNetworkNumber) to UBound(ObjIP.IPXNetworkNumber)
				wscript.echo "Adapter IPX Network Number:" & ObjIP.IPXNetworkNumber(i)
			next
			wscript.echo "Adapter IPX Virtual Net Number:" & ObjIP.IPXVirtualNetNumber
		end if
	next
set IPConfigSet = nothing
End Function

Function getNetConnectionID(index,computername)
Dim NICConfigSet,nicobj
set OSGet = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computername & "\root\cimv2").ExecQuery _
	("SELECT Caption FROM Win32_OperatingSystem")
	for each OSobj in OSGet
		set NICConfigSet = GetObject("winmgmts:{impersonationLevel=impersonate}\\" & computername & "\root\cimv2").ExecQuery _
				("SELECT * FROM Win32_NetworkAdapter Where Index = " & index & "")
				for each nicobj in NICConfigSet
					if instr(1,OSobj.Caption,"2003") or instr(1,OSobj.Caption,"XP") then
						getNetConnectionID = nicobj.NetConnectionID
					else
						getNetConnectionID = "N/A"
					end if
				next
		set NICConfigSet = nothing	
	next
End Function

Function convertTime(contime)
On Error Resume Next
Dim tolry,tolrm,tolrd,tolrh,tolrmi,tolrs
	tolry = Left(contime,4)
	tolrm = Mid(contime,5,2)
	tolrd = Mid(contime,7,2)
	tolrh = Mid(contime,9,2)
	tolrmi = Mid(contime,11,2)
	tolrs = Mid(contime,13,2)
	convertTime = TimeSerial(tolrh,tolrmi,tolrhs) & "  " & DateSerial(tolry,tolrm,tolrd)
End Function

Function errorChecking(ComputerName) 
errorChecking = False 
if err.number <> 0 then 
	wscript.echo "Unable to connect to " & ucase(ComputerName)
	err.Clear () 
	errorChecking = True
end if 
end Function
