Jump to content

List Networked Computers


Recommended Posts

I'm reasonably sure this has been done but I can't find it.

I need to get a list of all the computers (by name) connected to a network, without using WMI. I've done it with WMI before but this time I don't want to use that method.

Thanks all

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

@GEOSoft

Something like this can get you started

#include<GuiListView.au3>
#include<Array.au3>
#include<GUIConstantsEx.au3>
#include<ListViewConstants.au3>
GUICreate("NetView in ListView", 520, 550, 100, 100, -1)
;GUISetBkColor(0x00E0FFFF)  ; will change background color

$listview = GUICtrlCreateListView("Computer Name|Description|IP Address", 10, 10, 500, 520, Default, $LVS_EX_GRIDLINES)
_GUICtrlListView_SetColumnWidth($listview, 2, $LVSCW_AUTOSIZE_USEHEADER)

Global $s_Comments[1], $n_IP[1]
Global $s_Servernames = Net_View()

For $i = 0 To UBound($s_Servernames) - 1
    GUICtrlCreateListViewItem($s_Servernames[$i] & '|' & $s_Comments[$i] & '|' & $n_IP[$i], $listview)
Next
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit (0)
    EndSwitch
WEnd

Func Net_View()
    Local $s_Buf = ''
    Local $a_Buf = ''
    Local $i_Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 2 + 4)
    While Not @error
        $s_Buf &= StdoutRead($i_Pid)
    WEnd
    Local $netView_Lines = StringSplit($s_Buf, @LF)
    ReDim $s_Comments[UBound($netView_Lines) ]
    For $i = 4 To UBound($netView_Lines) - 1
        $s_Comments[$i - 4] = StringMid($netView_Lines[$i], 24, 30)
    Next
    $a_Buf = StringRegExp($s_Buf, "\\\\([0-9a-zA-Z-_]*)", 3) ; Start at line 3 and match \\ any of these chars "0-9, a-z, A-Z, -, _"
    ReDim $n_IP[UBound($a_Buf) ]
    TCPStartup()
    For $i = 1 TO UBound($a_Buf) -1
        $n_IP[$i] = TCPNameToIP($a_Buf[$i]) ; Get IPaddresses
    Next
    TCPShutdown ( )
    ProcessClose($i_Pid)
    Return $a_Buf
EndFunc   ;==>Net_View

Regards,

ptrex

Link to comment
Share on other sites

Thanks both of you. That was just too basic. Don't know where my head is at today. I can just Run Net View and parse the StdOut with a RegExp.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Here is what I ended up with and it works fine.

Func _ListComputers()
   Local $rArray, $Buff, $Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 6)
   While Not @error
      $buff &= StdoutRead($Pid)
   WEnd
   $rArray = StringRegExp($Buff, "[\\]+([\w-]+)", 3)
   If @Error Then $rArray = StringRegExp(@ComputerName, "(.+)", 1)
   Return $rArray
EndFunc

Edit: mistakingly used quote tags instead of code tags

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

GEOSoft

Another solution

That I believe may be the one I was thinking of before. I knew I had seen it. The one I posted is short and simple. However there is still going to be a problem with the application itself. The idea behind getting the Computer names was to be able to enumerate the drives on all the computers and then perform file operations on certain files. That is a bit more difficult to do and I have not been able to get it working yet. I think the script will end up having to be run locally on each computer which means that listing the computers, in this case, was all for naught. Bummer. It's a virus removal tool so It would have been nice to check the whole network at one time.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • 3 years later...

Here is what I ended up with and it works fine.

Func _ListComputers()
   Local $rArray, $Buff, $Pid = Run(@ComSpec & ' /c net view', '', @SW_HIDE, 6)
   While Not @error
      $buff &= StdoutRead($Pid)
   WEnd
   $rArray = StringRegExp($Buff, "[\\]+([\w-]+)", 3)
   If @Error Then $rArray = StringRegExp(@ComputerName, "(.+)", 1)
   Return $rArray
EndFunc

Edit: mistakingly used quote tags instead of code tags

Sorry to bring this thread back from the dead.

Could anyone help by telling me how could I use this code (or any like it) to get the output into a combobox or list dropdown to have an end-user select the appropriate computer found on the network?

Thank you for your help.

Link to comment
Share on other sites

$aComputers = _ListComputers();; That's the function posted above.

$sData = ""
For $i = 0 To Ubound($aComputers) -1
    $sData &= $aComputers[$i] & "|"
Next
GuiCtrlSetData($SomeCombobox, StringTrimRight($sData, 1), $aComputers[1])

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

$aComputers = _ListComputers();; That's the function posted above.

$sData = ""
For $i = 0 To Ubound($aComputers) -1
    $sData &= $aComputers[$i] & "|"
Next
GuiCtrlSetData($SomeCombobox, StringTrimRight($sData, 1), $aComputers[1])

Thank you so much for the quick reply!

I can't wait to try it out.

I'm still trying to learn more about Ubound so I wouldn't have figured this out alone for some time (if ever) :). (I'm also trying to learn to recreate .vbs scripts into autoit myself so I can implement wmi better into my code).

Thank you again, GeoSoft!

Edited by coffeeturtle
Link to comment
Share on other sites

Here is a function with a sample Call that you can re-use it without having to duplicate code for several controls

GuiCtrlSetData($SomeCombobox, _ArrayToList($aComputers), $aComputers[0]);; Here we are setting the list and making the first computer ([0]) in the array default

Func _ArrayToList($a_Array, $i_Ubound = 0)
    If NOT IsArray($a_Array) Then Return SetError(1,1, "The parameter must be an array")
    Local $s_Rtn = "", $s_Sep = Opt("GUIDataSeparatorChar")
    For $i = 0 To $i_Ubound -1
        $s_Rtn &= $a_Array[$i] & $s_Sep
    Next
    Return (StringTrimRight($s_Rtn, StringLen($s_Sep)))
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Here is a function with a sample Call that you can re-use it without having to duplicate code for several controls

GuiCtrlSetData($SomeCombobox, _ArrayToList($aComputers), $aComputers[0]);; Here we are setting the list and making the first computer ([0]) in the array default

Func _ArrayToList($a_Array, $i_Ubound = 0)
    If NOT IsArray($a_Array) Then Return SetError(1,1, "The parameter must be an array")
    Local $s_Rtn = "", $s_Sep = Opt("GUIDataSeparatorChar")
    For $i = 0 To $i_Ubound -1
        $s_Rtn &= $a_Array[$i] & $s_Sep
    Next
    Return (StringTrimRight($s_Rtn, StringLen($s_Sep)))
EndFunc

Thank you again GeoSoft. That is very kind of you! I've just gotten back so I will be using this right away (and learn a few things in the process). :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...