Jump to content
Sign in to follow this  
GodlessSinner

How to get list of ALL network adapters?

Recommended Posts

GodlessSinner
Including disconnected adapters. Please help.

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
FireFox

You can do this with the Winpcap library. There may be WinAPI solutions somewhere.

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
GodlessSinner

I can't found nothing about network in WinApi Management in Help.chm. What is Winpcap and how to use it in AutoIt or C#?


_____________________________________________________________________________

Share this post


Link to post
Share on other sites
UEZ

Try this:

#include <Array.au3>
$sHost = @ComputerName
$aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost)

_ArrayDisplay($aNetworkAdapters)

Func WMI_ListAllNetworkAdapters($sHost) ;coded by UEZ 2013
    Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2")
    If @error Then Return SetError(1, 0, 0)
    Local $aStatus[13] = ["Disconnected", "Connecting", "Connected", "Disconnecting", "Hardware not present", "Hardware disabled", "Hardware malfunction", _
                          "Media Disconnected", "Authenticating", "Authentication Succeeded", "Authentication Failed", "Invalid Address", "Credentials Required"]
    $colItems = $objWMIService.ExecQuery("SELECT Name, NetConnectionID, NetConnectionStatus FROM Win32_NetworkAdapter", "WQL", 0x30)
    Local $aNetworkAdapters[1000][3], $i = 0, $iPointer
    If IsObj($colItems) Then
        For $objItem in $colItems
            With $objItem
                $aNetworkAdapters[$i][0] = .NetConnectionID
                $aNetworkAdapters[$i][1] = .Name
                $aNetworkAdapters[$i][2] = $aStatus[.NetConnectionStatus * 1]
            EndWith
            $i += 1
        Next
        ReDim $aNetworkAdapters[$i][3]
        Return $aNetworkAdapters
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc

Br,

UEZ

Edited by UEZ
  • Like 1

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
GodlessSinner

Try this:

#include <Array.au3>
$sHost = @ComputerName
$aNetworkAdapters = WMI_ListAllNetworkAdapters($sHost)

_ArrayDisplay($aNetworkAdapters)

Func WMI_ListAllNetworkAdapters($sHost) ;coded by UEZ 2013
Local $objWMIService = ObjGet("winmgmts:\\" & $sHost & "\root\cimv2")
If @error Then Return SetError(1, 0, 0)
$colItems = $objWMIService.ExecQuery("SELECT Name, NetConnectionID FROM Win32_NetworkAdapter WHERE NetConnectionStatus IS NOT NULL", "WQL", 0x30)
Local $aNetworkAdapters[1000][2], $i = 0
If IsObj($colItems) Then
For $objItem in $colItems
With $objItem
$aNetworkAdapters[$i][0] = .NetConnectionID
$aNetworkAdapters[$i][1] = .Name
EndWith
$i += 1
Next
ReDim $aNetworkAdapters[$i][2]
Return $aNetworkAdapters
Else
Return SetError(2, 0, 0)
EndIf
EndFunc

Br,

UEZ

Thanks, but it returns only connected adapters, but I need ALL, I tried also without "WHERE NetConnectionStatus IS NOT NULL", and it doesn't returns disconnected adapters.

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
UEZ

I've update the code from post#6. Please try it again. It can be that the NetConnectionID is empty. Check out for the name.

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
GodlessSinner

I've update the code from post#6. Please try it again. It can be that the NetConnectionID is empty. Check out for the name.

Thanks, but it doesn't returns my disconected ppp(modem) adapters. Code return's only names of local connections.. Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
JohnOne

$objWMIService = ObjGet("winmgmts:\\.\root\cimv2")
If Not IsObj($objWMIService) Then
    MsgBox(0,"Error","$objWMIService Not Object")
    Exit
EndIf
$sQuery = "Select * from Win32_NetworkAdapter"
$colItems = $objWMIService.ExecQuery ($sQuery)
If Not IsObj($colItems) Then
    MsgBox(0,"Error","$objWMIService Not Object")
    Exit
EndIf
;MsgBox(0,0,VarGetType($colItems))
$sResult = ""
$count = 0
For $objItem In $colItems
    $count += 1

    ;$sResult &= "Index: " & $objItem.WINSScopeID & @CRLF
    ;$sResult &= "Caption: " & $objItem.Caption & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "Name: " & $objItem.Name & @CRLF
    $sResult &= "Description: " & $objItem.Description & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "MACAddress: " & $objItem.MACAddress & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "NetConnectionStatus: " & $objItem.NetConnectionStatus & @CRLF
    ;ConsoleWrite("> " & $sResult)
    $sResult &= "GUID: " & $objItem.GUID & @CRLF
    ;For $strIPAddress In $objItem.IPAddress
    ;    $sResult &= "IPAddress: " & $strIPAddress & @CRLF
    ;Next
    $sResult &= @CRLF
Next
ConsoleWrite("There are " & $count & " devices available" & @LF & @LF)
ConsoleWrite($sResult & @LF)

  • Like 1

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
GodlessSinner

Your code doesn't returns even connected internet(modem) adapters.

It's seems impossible in C# and AutoIt and it can't be done via registry.

Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
GodlessSinner

Are you talking about dial up/phone line modems?

Yes, dial up/3G modem Edited by GodlessSinner

_____________________________________________________________________________

Share this post


Link to post
Share on other sites
GodlessSinner

I have searched for it in most programing languages and it seems like impossible... Sad.


_____________________________________________________________________________

Share this post


Link to post
Share on other sites
FireFox

The snippets provided work well, make sure you run them with admin rights (or add #RequireAdmin)

Br, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.