jvanegmond Posted March 25, 2007 Share Posted March 25, 2007 I've been thinking about this for a while, but I can't make a decision..I'm trying to get all online computers in a network, not just a workgroup and I have 2 possible choices:1. 'net view'Running the 'net view' command, and parsing the output, to get all the computer names (net names?) that are online.Using TCPNameToIP or parse the output of the Ping command, to get the ip.Downside: This only works for computers in a workgroup. You have to allow for manually add IP's.Upside: Reasonably fast.2. Generic IP scanI've just finished using this method. This gets the first 3 numbers in an IP. (Like 192.168.2.x) Then ping's all these computers, and uses nbtstat -A to get the computer name (and Mac address)..Downside: This does not work in networks that have an odd netmask, as the IP's are different. Very very slow.Upside: Auto configures everything.Thanks. github.com/jvanegmond Link to comment Share on other sites More sharing options...
Valuater Posted March 25, 2007 Share Posted March 25, 2007 Just incase you want to parse the net view I hope this can help you expandcollapse popup; temporary script Dim $un = @UserName Dim $QT_web = "www.ClickTask.com" $ver = "1.0" ;delete last listing Filedelete(@TempDir & "\a.tmp") Filedelete(@TempDir & "\b.tmp") ; make sure net send is running RunWait("net start messenger","",@SW_HIDE) ;gets the computer list and a few other things RunWait(@ComSpec & ' /c net view > ' & @TempDir & '\a.tmp',"", @SW_HIDE) Sleep(300) ;open the file for working $file = FileOpen(@TempDir & "\a.tmp", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "QT - Error", "Unable to open file.") Exit EndIf ;Creates new file in which the result will be written FileOpen(@TempDir & "\b.tmp", 1) ; Read in lines of text until the EOF is reached in file a.tmp While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;find the string "\\" $result = StringInStr($line,"\\") if $result = 1 Then ;find next blank $blankpos = StringInStr($line," ") ;Find length of line $len = StringLen($line) ;calculate from what position to Trim string to the right $len = $len - $blankpos ;Trim all characters after the computer name $line = StringTrimRight($line, $len) ;Trim the // $line = StringTrimLeft($line,2) ;Write line to file, adding "|" FileWrite(@TempDir & "\b.tmp", $line & "|") EndIf Wend FileClose($file) FileDelete(@TempDir & "\a.tmp") $file2 = FileReadline(@TempDir & "\b.tmp", 1) ;install pics $Time_Logo = @TempDir & "\Time-logo.jpg" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Time.jpg", $Time_Logo) $Time_icon = @TempDir & "\Time-Icon.ico" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Time-Icon.ico", $Time_icon) $Sound_clk = @TempDir & "\Sound_clk.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Clickerx.wav", $Sound_clk) $Sound_grp = @TempDir & "\Sound_grp.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Group_open.wav", $Sound_grp) $Sound_bar = @TempDir & "\Sound_bar.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\xpinfbar.wav", $Sound_bar) $Sound_lnk = @TempDir & "\Sound_lnk.wav" FileInstall("C:\XPClean-web\Settings\XPClean-pics\Sounds\Notify.wav", $Sound_lnk) ;GUI Start #include "GUIConstants.au3" ;#include <Process.au3> ;Set GUI Opt("GUICoordMode", 1) ;Opt("GUINotifyMode", 1) $Dummy_win = GUICreate('') $Tmesg_win = GuiCreate("*QTime Station* - PC Messenger ver " & $ver, 482, 335, -1, -1,-1,$WS_EX_ACCEPTFILES,$Dummy_win);, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) GUISetFont(9, 400, -1, "MS Sans Serif") GUISetIcon($Time_icon) $Icon_1 = GUICtrlCreatePic($Time_Logo, 393, 10, 75, 70) GUICtrlSetCursor(-1, 0) GUICtrlSetTip(-1, "ClickTask.com") $Group_1A = GuiCtrlCreateGroup( "Message from: ", 20, 10, 350, 50) GUICtrlCreateLabel( $un, 40, 30, 150, 20) ;Create 1 combo box, give focus and populate with contents of b.tmp $Group_1A = GuiCtrlCreateGroup("Message to: ",20, 70, 350, 50) $combo_1 = GUICtrlCreateCombo("", 130, 87, 120, 20) GUICtrlSetState(-1,$GUI_FOCUS) GUICtrlSetData(-1,$file2) $label_1 = GUICtrlCreateLabel( "C&hoose the PC", 40, 90, 80, 20) $Group_4 = GuiCtrlCreateGroup("Last Message Sent", 20, 270, 350, 50) $MSent = GUICtrlCreateLabel("No Recent Messages", 40, 288, 320, 28) ;Create buttons $button_1 = GUICtrlCreateButton("S&end", 390, 190, 80, 30) GUICtrlSetState(-1,$GUI_DEFBUTTON) $button_2 = GUICtrlCreateButton("Set-Up", 390, 275, 80, 20) $button_3 = GUICtrlCreateButton("C&ancel", 390, 300, 80, 20) ;create text input $Group_3 = GuiCtrlCreateGroup("Message Text", 20, 140, 350, 120) GUICtrlCreateLabel("Please Type in Your Test Message in the Box Below", 40, 165, 310, 20) GUICtrlCreateLabel("The Message includes the Time, Date, PC and Sender Name", 40, 185, 320, 20) $text = GUICtrlCreateInput("Message", 40, 215, 310, 20) ;Show the GUI GuiSetState (@SW_SHOW) SoundPlay ($Sound_lnk,1) ;sets tray icon opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown. opt("TrayOnEventMode", 1) ;TraySetClick (16); right click $show_tray = TrayCreateItem ("Show *QTime Station*") TrayItemSetOnEvent (-1, "Set_Show") TrayCreateItem ("") $upgrade_tray = TrayCreateItem ("Check New Releases") TrayItemSetOnEvent (-1, "Set_Update") TrayCreateItem ("") $setup_tray = TrayCreateItem ("Net-Send Setup") TrayItemSetOnEvent (-1, "Set_Setup") TrayCreateItem ("") $about_tray = TrayCreateItem ("About ClickTask.com") TrayItemSetOnEvent (-1, "Set_QT") TrayCreateItem ("") $exit_tray = TrayCreateItem ("Exit *QTime Station*") TrayItemSetOnEvent (-1, "Set_Exit") TraySetState () $msg = 0 While 1; $msg <> -3 $msg = GuiGetMsg() Select case $msg = $button_3 Or $msg = $GUI_EVENT_CLOSE GUISetState(@SW_HIDE, $Tmesg_win) SoundPlay ($Sound_grp,1) case $msg = $button_2 ;SoundPlay ($Sound_clk,1) Call("Set_Setup") case $msg = $button_1 SoundPlay ($Sound_clk,1) $CPUID = GuictrlRead($combo_1) If $CPUID = "" Then MsgBox(64,"Send Error 1"," Please choose a PC to *Send* to... ") ContinueLoop EndIf $msg1 = GuictrlRead($text) If $msg1 = "" Or $msg1 = "Message" Then MsgBox(64,"Send Error 2"," Please Type a *Text Message* First... " ) ContinueLoop EndIf $runvar =RunWait(@comspec & " /c net send " & $CPUID & $un & " says: " & $msg1,"",@sw_hide) ;MsgBox(0,"",$runvar) If $runvar > 0 Then MsgBox(64,"Send Error 3"," Your Message *Could Not Be Sent* " & @CRLF & @CRLF & " Please press the *Set-Up* Button " & @CRLF & @CRLF & "and press *Set-Up* on " & $CPUID & " " ) ContinueLoop EndIf GUICtrlSetData ( $MSent, $msg1) EndSelect WEnd Exit ;---------------------------- FUNCTIONS ---------------------- Func Set_Update() SoundPlay ($Sound_clk,1) Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $QT_web) WinWaitActive("") EndFunc Func Set_Show() SoundPlay ($Sound_grp,1) GUISetState(@SW_SHOW, $Tmesg_win) EndFunc Func Set_QT() SoundPlay ($Sound_grp,1) $iMsgBoxAnswer = MsgBox(32, "*QTime Station* , by QTasc (Now ClickTask.com)", "WHO IS, QT APPRAISAL SERVICE CO ?" & @CRLF & "" & @CRLF & "We are a Real Estate Appraisal Company based in Riverside, California. " & @CRLF & "" & @CRLF & "Thank you." & @CRLF & "" & @CRLF & "", 60) Select Case $iMsgBoxAnswer = -1;Timeout EndSelect SoundPlay ($Sound_grp,1) EndFunc Func Set_Exit() SoundPlay ($Sound_lnk,1) Exit EndFunc ;==>Set_Exit Func Set_Setup() SoundPlay ($Sound_clk,1) GUISetState(@SW_HIDE, $Tmesg_win) Run("mmc Services.msc -k netsvcs", @SystemDir) WinWaitActive("Services") Sleep(300) Send("{TAB}") Sleep(300) Send("Messenger") Sleep(300) Send("{ENTER}") Sleep(300) Send("!e") Sleep(300) Send("A") Sleep(300) Send("!A") Sleep(300) Send("!S") Sleep(2000) MsgBox(64,"Finished Set-up"," If all settings are satisfactory... " & @CRLF & " Please press *OK* ") While 3 If Not WinExists("Messenger Properties") Then ExitLoop Sleep(100) WEnd Sleep(100) WinClose("Services") EndFunc ;==>Set_Exit Exit Func OnAutoItStart() If WinExists(@ScriptName & '_Interpreter') Then Exit AutoItWinSetTitle(@ScriptName & '_Interpreter') EndFunc 8) Link to comment Share on other sites More sharing options...
jvanegmond Posted March 25, 2007 Author Share Posted March 25, 2007 Val, you've got me convinced. Why write the output of net view to a file and then read it? Isn't StdOutRead for that stuff? github.com/jvanegmond Link to comment Share on other sites More sharing options...
Valuater Posted March 26, 2007 Share Posted March 26, 2007 (edited) Val, you've got me convinced. Why write the output of net view to a file and then read it? Isn't StdOutRead for that stuff?Actually, I believe this was done just before or just as StdOutRead was released8) Edited March 26, 2007 by Valuater Link to comment Share on other sites More sharing options...
jinxter Posted March 26, 2007 Share Posted March 26, 2007 seems like net view gives you all online computers within your subnet (haven't looked if you can do a lookup in a different network). So it might not help you trying to find computers on different subnets... > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
jvanegmond Posted March 26, 2007 Author Share Posted March 26, 2007 seems like net view gives you all online computers within your subnet (haven't looked if you can do a lookup in a different network). So it might not help you trying to find computers on different subnets...I know, that was the downside of 'net view' which I posted in my initial post.. Otherwise, I would have gone for this approach a long time ago! github.com/jvanegmond Link to comment Share on other sites More sharing options...
jinxter Posted March 27, 2007 Share Posted March 27, 2007 1. 'net view'Running the 'net view' command, and parsing the output, to get all the computer names (net names?) that are online.Using TCPNameToIP or parse the output of the Ping command, to get the ip.Downside: This only works for computers in a workgroup. You have to allow for manually add IP's.Upside: Reasonably fast.just to clearify, subnet is not the same as workgroup. You can be in different workgroups, but still in the same subnet. net view will show all online computers in the same subnet, no matter what workgroup they're in. (or domain)I know, that was the downside of 'net view' which I posted in my initial post.. Otherwise, I would have gone for this approach a long time ago!Dude, I'm on your side It will probably be hard to get all IP's in a network (forget subnets) without the use of the DHCP or DNS servers, of course you could sniff the network for broadcasts, but it will not work if you're on a VLAN configured network (which I would say is not that uncommon). you could try nslookup and see what that will bring you (not saying it will help you). Network related problems are really not my strongest skill, so forgive me if I'm wrong here . > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
jvanegmond Posted March 27, 2007 Author Share Posted March 27, 2007 just to clearify, subnet is not the same as workgroup. You can be in different workgroups, but still in the same subnet. net view will show all online computers in the same subnet, no matter what workgroup they're in. (or domain) Dude, I'm on your side It will probably be hard to get all IP's in a network (forget subnets) without the use of the DHCP or DNS servers, of course you could sniff the network for broadcasts, but it will not work if you're on a VLAN configured network (which I would say is not that uncommon). you could try nslookup and see what that will bring you (not saying it will help you). Network related problems are really not my strongest skill, so forgive me if I'm wrong here . Sorry, I didn't mean to be offensive. Here's how Microsoft describes 'net view'. http://support.microsoft.com/kb/310381/en If you use the net view command without command-line parameters, or with the /domain switch, a list of computers in the domain or workgroup is displayed. For example, to view a list of computers in your current domain or workgroup, type the following: net view No subnets mentioned, so I guess this is for the entire workgroup. @Valuater, #include <Constants.au3> $PID = Run("cmd /c net view","",@SW_HIDE,$STDOUT_CHILD+$STDERR_CHILD) Dim $Read = '', $ErrorRead = '' While ProcessExists($PID) $Read &= StdoutRead($PID) $ErrorRead &= StderrRead($PID) WEnd $Read &= StdoutRead($PID) $ErrorRead &= StderrRead($PID) FileWrite(@DesktopDir & "\NetViewReport.txt","###Out stream: " & @CRLF & $Read & @CRLF & "###Error stream: " & @CRLF & $ErrorRead & @CRLF & "###RegExp result:" & @CRLF) $ComputerName = StringRegExp($Read,"\\\\([^ ]*)",3) If @error Then FileWrite(@DesktopDir & "\NetViewReport.txt","Error code: " & @error) Else For $x = 0 To UBound($ComputerName)-1 FileWrite(@DesktopDir & "\NetViewReport.txt",$ComputerName[$x] & @CRLF) Next EndIf Here's a little test something. I have a mate that gets an 6118 error using 'net view'.. Sounds familiar? :? github.com/jvanegmond Link to comment Share on other sites More sharing options...
jinxter Posted March 28, 2007 Share Posted March 28, 2007 Sorry, I didn't mean to be offensive.no worries mate No subnets mentioned, so I guess this is for the entire workgroup.apperently net works for netware aswell, so I guess subnets is out of the question. well... as long as you don't use netware I would say net view will show all your online computers in your subnet. I can't verify this though, as we're in a domain and I don't want to leave the domain for obvious reasons. > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
Uten Posted March 28, 2007 Share Posted March 28, 2007 ... I'm trying to get all online computers in a network, not just a workgroup and I have 2 possible choices: ... 2. Generic IP scan I've just finished using this method. This gets the first 3 numbers in an IP. (Like 192.168.2.x) Then ping's all these computers, and uses nbtstat -A to get the computer name (and Mac address).. Downside: This does not work in networks that have an odd netmask, as the IP's are different. Very very slow. Upside: Auto configures everything. Thanks.Why is it slow? Are you referring to the native or the AutoIt one? Do you know the nature of your network? If it is fast you could do something like: ping -w 1 -n 1 10.0.0.1 There are probably other ways to tweak this considering the speed of all the network scanning tools out there. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
jinxter Posted March 28, 2007 Share Posted March 28, 2007 ping -w 1 -n 1 10.0.0.1 if you add a -a to the mix you get a resolve of the hostname aswell. > there are 10 types of people in the world, those who understand binary and those who don't. Link to comment Share on other sites More sharing options...
ptrex Posted March 28, 2007 Share Posted March 28, 2007 @all Maybe this can help. #include <array.au3> Dim $objArgs[1] Dim $objDomain Dim $objComputer $objArgs[0] = "Domain1" ; Domain 2 $objShell = ObjCreate("WScript.Shell") $objFSO = ObjCreate("Scripting.FileSystemObject") $objDomain = ObjGet("WinNT://" & $objArgs[0]) $objDomain.Filter = _ArrayCreate("computer") If $objFSO.FileExists($objArgs[0] & ".txt") = 1 Then $objFSO.DeleteFile($objArgs[0] & ".txt") EndIf $txtOutput = $objFSO.CreateTextFile ($objArgs[0] & ".txt") For $objComputer In $objDomain $strComputer = $objComputer.Name $txtOutput.Writeline ($objArgs[0] & "\" & $strComputer) Next Regards, ptrex 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...
jvanegmond Posted March 30, 2007 Author Share Posted March 30, 2007 (edited) Why is it slow? Are you referring to the native or the AutoIt one? Do you know the nature of your network? If it is fast you could do something like: ping -w 1 -n 1 10.0.0.1 There are probably other ways to tweak this considering the speed of all the network scanning tools out there. AutoIt is slow for this purpose, as I used this technique: $IP = @IPAddress1 If $IP == "127.0.0.1" Then SplashOff() MsgBox(0x10,$AppTitle,"You do not have an network connection available.. This program will now exit.") Exit EndIf $IP = StringSplit($IP,".") If $IP[0] <> 4 Then SplashOff() MsgBox(0x10, $AppTitle, "This version of the " & $AppTitle & " does not support IPv6. Please go to " & $Website & " to get the latest version.") Exit Else $IPPrefix = $IP[1] & "." & $IP[2] & "." & $IP[3] & "." EndIf For $x = 0 To 255 $ICMP = Ping($IPPrefix & $x, $TimeOut) If $ICMP Then $dComputer[$i][0] = $IPPrefix & $x $dComputer[$i][4] = $ICMP IniWrite($SettingFile,"Network",$dComputer[$i][0],$ICMP) $i += 1 EndIf GUICtrlSetData(-1,Int($x/255*100)) Next This is just part of it, but it is as clear as glass that this is not a proper way to do this.. Edited March 30, 2007 by Manadar github.com/jvanegmond 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