erebus Posted February 1, 2007 Share Posted February 1, 2007 (edited) Hello, I have written a small script to find all the network interfaces on a system: Global $nicid[11], $nicdesc[11], $nicdhcpip[11], $nicstaticip[11] For $i = 1 To 10 ; Get the first 10 cards on the system $nicid[$i] = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards", $i) $nicdesc[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $nicid[$i], "Description") $nicid[$i] = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\" & $nicid[$i], "ServiceName") $nicdhcpip[$i] = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $nicid[$i], "DhcpIPAddress") $nicstaticip[$i] = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\" & $nicid[$i], "IPAddress") $nicid[0] = $i - 1 If @error <> 0 then ExitLoop Next For $i = 1 To $nicid[0] MsgBox(64, "FlipGate v0.0 - http://www.unicode.gr", "Total cards found: " & $nicid[0] & @LF & @LF & "NIC: " & $nicdesc[$i] & @LF & "DHCP IP: " & $nicdhcpip[$i] & @LF & "Static IP: " & $nicstaticip) Next The question is, how can I find the ACTIVE(s) network interface(s) on the system? Either using registry or WMI, DLL whatever... Edited February 1, 2007 by erebus Link to comment Share on other sites More sharing options...
ptrex Posted February 1, 2007 Share Posted February 1, 2007 @erebus This will list all your adapters : expandcollapse popup; Generated by AutoIt Scriptomatic $wbemFlagReturnImmediately = 0x10 $wbemFlagForwardOnly = 0x20 $colItems = "" $strComputer = "localhost" $Output="" $Output = $Output & "Computer: " & $strComputer & @CRLF $Output = $Output & "==========================================" & @CRLF $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter", "WQL", _ $wbemFlagReturnImmediately + $wbemFlagForwardOnly) If IsObj($colItems) then For $objItem In $colItems $Output = $Output & "AdapterType: " & $objItem.AdapterType & @CRLF $Output = $Output & "AdapterTypeId: " & $objItem.AdapterTypeId & @CRLF $Output = $Output & "AutoSense: " & $objItem.AutoSense & @CRLF $Output = $Output & "Availability: " & $objItem.Availability & @CRLF $Output = $Output & "Caption: " & $objItem.Caption & @CRLF $Output = $Output & "ConfigManagerErrorCode: " & $objItem.ConfigManagerErrorCode & @CRLF $Output = $Output & "ConfigManagerUserConfig: " & $objItem.ConfigManagerUserConfig & @CRLF $Output = $Output & "CreationClassName: " & $objItem.CreationClassName & @CRLF $Output = $Output & "Description: " & $objItem.Description & @CRLF $Output = $Output & "DeviceID: " & $objItem.DeviceID & @CRLF $Output = $Output & "ErrorCleared: " & $objItem.ErrorCleared & @CRLF $Output = $Output & "ErrorDescription: " & $objItem.ErrorDescription & @CRLF $Output = $Output & "Index: " & $objItem.Index & @CRLF $Output = $Output & "InstallDate: " & WMIDateStringToDate($objItem.InstallDate) & @CRLF $Output = $Output & "Installed: " & $objItem.Installed & @CRLF $Output = $Output & "LastErrorCode: " & $objItem.LastErrorCode & @CRLF $Output = $Output & "MACAddress: " & $objItem.MACAddress & @CRLF $Output = $Output & "Manufacturer: " & $objItem.Manufacturer & @CRLF $Output = $Output & "MaxNumberControlled: " & $objItem.MaxNumberControlled & @CRLF $Output = $Output & "MaxSpeed: " & $objItem.MaxSpeed & @CRLF $Output = $Output & "Name: " & $objItem.Name & @CRLF $Output = $Output & "NetConnectionID: " & $objItem.NetConnectionID & @CRLF $Output = $Output & "NetConnectionStatus: " & $objItem.NetConnectionStatus & @CRLF $strNetworkAddresses = $objItem.NetworkAddresses(0) $Output = $Output & "NetworkAddresses: " & $strNetworkAddresses & @CRLF $Output = $Output & "PermanentAddress: " & $objItem.PermanentAddress & @CRLF $Output = $Output & "PNPDeviceID: " & $objItem.PNPDeviceID & @CRLF $strPowerManagementCapabilities = $objItem.PowerManagementCapabilities(0) $Output = $Output & "PowerManagementCapabilities: " & $strPowerManagementCapabilities & @CRLF $Output = $Output & "PowerManagementSupported: " & $objItem.PowerManagementSupported & @CRLF $Output = $Output & "ProductName: " & $objItem.ProductName & @CRLF $Output = $Output & "ServiceName: " & $objItem.ServiceName & @CRLF $Output = $Output & "Speed: " & $objItem.Speed & @CRLF $Output = $Output & "Status: " & $objItem.Status & @CRLF $Output = $Output & "StatusInfo: " & $objItem.StatusInfo & @CRLF $Output = $Output & "SystemCreationClassName: " & $objItem.SystemCreationClassName & @CRLF $Output = $Output & "SystemName: " & $objItem.SystemName & @CRLF $Output = $Output & "TimeOfLastReset: " & WMIDateStringToDate($objItem.TimeOfLastReset) & @CRLF if Msgbox(1,"WMI Output",$Output) = 2 then ExitLoop $Output="" Next Else Msgbox(0,"WMI Output","No WMI Objects Found for class: " & "Win32_NetworkAdapter" ) Endif Func WMIDateStringToDate($dtmDate) Return (StringMid($dtmDate, 5, 2) & "/" & _ StringMid($dtmDate, 7, 2) & "/" & StringLeft($dtmDate, 4) _ & " " & StringMid($dtmDate, 9, 2) & ":" & StringMid($dtmDate, 11, 2) & ":" & StringMid($dtmDate,13, 2)) EndFunc And this will show all information about the adaptors. And if I remember well check the output called "NetConnectionStatus" = 2 regards ptrex Parsix 1 Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
FreeRider Posted February 1, 2007 Share Posted February 1, 2007 Hello ptrex is correct.... "NetConnectionStatus" = 2 means the adapter is active but sometimes this status is also used when the adapter is acquiring network (not yet connected). So in most cases you wont have any poblem but just be aware you could. FreeRiderHonour & Fidelity Link to comment Share on other sites More sharing options...
oneLess Posted December 18, 2007 Share Posted December 18, 2007 Hello ptrex is correct.... "NetConnectionStatus" = 2 means the adapter is active but sometimes this status is also used when the adapter is acquiring network (not yet connected). So in most cases you wont have any poblem but just be aware you could. during the time when the adapter is acquiring network "NetConnectionStatus" is always 2 as value but the IP is 127.0.0.1 [at least here] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now