'========================================================================== ' NAME: IPInfo.vbs ' ' Alan Kaplan, original version 11/26/2002 (not the best example of clean coding) ' alan dot kaplan at va gov ' COMMENT: First change, 2005 added link speed ' 1-8-2007 Fixed DNS search order and added WAG for duplex setting. ' Duplex is a best guess value ' 1-9-2007 copy to clipboard added ' 1-27-2009 Some bug fixes for multiple nics ' 3-20-2009 Added default gateway. '========================================================================== Option Explicit Const HKEY_LOCAL_MACHINE = &H80000002 Dim message, strComputer Dim oWMI Dim strQuery, colitems, objItem, tarray, NICName, address, subnet, i Dim objReg, strKeyPath, arrSubKeys, subKey, strNICName,dwValue,bFound,NicMessage Dim oNDIS, oLink, suffix, strGateway, iPage iPage = 1 If WScript.Arguments.Count = 1 Then strComputer = WScript.Arguments(0) Else Dim WshShell Set wshShell = WScript.CreateObject("WScript.Shell") message = "Enter Name of PC to query WMI for IP information." strComputer = wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") strcomputer = InputBox(message, "WMI IP",strComputer) End If If strcomputer = "" Then WScript.Quit strComputer = UCase(strComputer) On Error Resume Next Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") strQuery = "Select * from Win32_NetworkAdapterConfiguration " & _ "where IPEnabled=True" Set colItems = oWMI.ExecQuery(strQuery,,48) If Err <> 0 Then MsgBox "Failed to query "&strcomputer,vbcritical&vbokonly,"Fatal Error" WScript.Quit End If For Each objItem in colitems If isArray(objItem.DefaultIPGateway) Then For i = 0 To UBound (objItem.DefaultIPGateway) strGateway = strGateway & objItem.DefaultIPGateway(0) & Space(1) Next Else strGateway = objItem.DefaultIPGateway End If 'Ignore NICs without Gateway If objItem.IPAddress(0) <> "0.0.0.0" And Len(objItem.IPAddress(0)) > 8 And Len(strGateway) >8 Then tArray = split(objItem.Caption,"] ") NicName = tArray(1) message = "NIC: " & NicName For Each address In objItem.IPAddress message = message & vbcrlf & "IP Address: " & address Next For Each subnet In objItem.IPSubnet message = message & vbcrlf & "IP Subnet: " & subnet Next message = message & vbcrlf & "Default Gateway: " & strGateway message = message & vbcrlf & "MAC Address: " & objItem.MACAddress message = message & vbcrlf & "DHCP Enabled: " & objItem.DHCPEnabled message = message & vbcrlf & "DHCP Server: " & objItem.DHCPServer message = message & vbcrlf & "DNS Domain: " & objItem.DNSDomain If IsArray(objItem.DNSDomainSuffixSearchOrder) Then message = message & VbCrLf & "DNS Domain Suffix Search Order: " For i = 0 To UBound(objItem.DNSDomainSuffixSearchOrder) message = message & objItem.DNSDomainSuffixSearchOrder(i) If i <> UBound(objItem.DNSDomainSuffixSearchOrder) Then message = message & ", " Next Else message = message & VbCrLf & "DNS Domain Suffix Search Order: " & objItem.DNSDomainSuffixSearchOrder End If message = message & vbcrlf & "DNS Enabled For WINS Resolution: " & objItem.DNSEnabledForWINSResolution If Not IsNull(objItem.DNSServerSearchOrder) Then For i = 0 to UBound(objItem.DNSServerSearchOrder) message = message & vbcrlf & "DNS Server #"&i +1 &": " & objItem.DNSServerSearchOrder(i) Next End If message = message & vbcrlf & "Domain DNS Registration Enabled: " & objItem.DomainDNSRegistrationEnabled message = message & vbcrlf & "Service Name: " & objItem.ServiceName message = message & vbcrlf & "WINS Enable LMHosts Lookup: " & objItem.WINSEnableLMHostsLookup message = message & vbcrlf & "WINS Host Lookup File: " & objItem.WINSHostLookupFile Dim strWin1, strWin2 strWin1 = objItem.WINSPrimaryServer strWin2 = objItem.WINSSecondaryServer If isNull(strWin1) Then strWin1 = VbCrLf If isnull(strWin2) Then strWin2 = VbCrLf message = message & vbcrlf & "WINS Primary Server: " & strWin1 message = message & vbcrlf & "WINS Secondary Server: " &strWin2 GetDuplex() NicMessage = "" Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\wmi") Set oNDIS = oWMI.ExecQuery("Select * from MSNDIS_LinkSpeed where InstanceName = '" & nicname & "'",,48) For Each oLink In oNDIS NicMessage = VbCrLf & "Last Link Speed: " & (oLink.NDISLinkSpeed / 10000) & " Mbps" Next if NicMessage = "" then NicMessage = VbCrLf & "(Link Speed Not Available)" message = message & NicMessage & VbCrLf On Error GoTo 0 'format width Dim strMessage, retval, iRepeat iRepeat = 35 Do while iRepeat < Len(NICName) iRepeat = iRepeat +1 Loop iRepeat = iRepeat -5 strmessage = message & VbCrLf & String(iRepeat,"=") & VbCrLf & "Copy information to clipboard via IE?" retval = MsgBox(strMessage,vbYesNo+vbdefaultbutton2, strcomputer & " IP Info, Page " & iPage) If retval = vbYes Then 'Use IE for clipboard Dim objIE Set objIE = CreateObject("InternetExplorer.Application") objIE.Navigate("about:blank") Do Until objIE.ReadyState=4: WScript.Sleep 1: Loop objIE.Document.ParentWindow.ClipboardData.SetData "Text", message objIE.Quit End If iPage = iPage + 1 End If Next Sub GetDuplex() ' COMMENT: Based in part on as script by RMAC461 found at ' http://www.scriptinganswers.com/archive/articles/NICSettings-SpeedandDuplex.htm Set objReg = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") If Err <> 0 Then MsgBox "Partial results. Failed to query registry on " & strComputer & ". " & Err.Description,vbINformation + vbOKOnly,"Error" Exit Sub End If strKeyPath = "System\Currentcontrolset\Control\Class\{4D36E972-E325-11CE-BFC1-08002be10318}" objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys Dim aKeys 'list of places to look aKeys = Array("DuplexMode","SpeedDuplex","RequestedMediaType","Media","Media_Type","MPMODE") For Each subkey In arrSubKeys For i = 0 to UBound (aKeys) GetInfo aKeys(i) If bFound Then Exit For Next Next End Sub Sub GetInfo(strValue) objReg.GetStringvalue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subkey,"DriverDesc", strNICName If strNICName <> NICName Then Exit Sub objReg.GetStringvalue HKEY_LOCAL_MACHINE, strKeyPath & "\" & subKey,strValue, dwValue If dwValue <> "" Then message = message & VbCrLf Lookup strNicName, strValue, dwValue bFound = True End If End Sub Sub Lookup (NicName,strKey,Val) ' What a pain! The duplex information will be right some of the time. ' You will probably need to edit it to detect the most common NICs in your domain Dim strDuplex If strKey = "MPMODE" Then 'AMD reverses ord Select Case Val Case 0 strDuplex = "Auto Detect" Case 1 strDuplex = "100Mb Half Duplex" Case 2 strDuplex = "100Mb Full Duplex" Case 3 strDuplex = "10Mb Half Duplex" Case 4 strDuplex = "10Mb Full Duplex" End Select ElseIf InStr(UCase(NicName), "BROADCOM") > 0 Then 'broadcom departs from numbering Select Case Val Case 0 strDuplex = "Auto Duplex" Case 3 strDuplex = "10Mb Half Duplex" Case 4 strDuplex = "10Mb Full Duplex" Case 5 strDuplex = "100Mb Half Duplex" Case 6 strDuplex = "100Mb Full Duplex" End Select Else Select Case val 'all other NICS? Case 0 strDuplex = "Auto Detect" Case 1 strDuplex = "10Mb Half Duplex" Case 2 strDuplex = "10Mb Full Duplex" Case 3 strDuplex = "100Mb Half Duplex" Case 4 strDuplex = "100Mb Full Duplex" Case 5 strDuplex = "1 Gigabit Full Duplex" ' another guess End Select End If message = message & "Duplex Registry Value: " & strKey & " = " & Val message = message & VbCrLf & "Duplex Setting is probably: " & strDuplex End Sub