RichE Posted June 15, 2011 Share Posted June 15, 2011 (edited) Hi All, I've a weird problem with one of my scripts,, it scans a range of IP addresses, if it gets a response it gets the workstation name and can create a list from these responding workstations , but... say I scan 5.1 through to 9.255 , it seems to be working, but it gets to 6.224 and hangs no console error in SciTE nothing, and I'm at a lose as to what could be causing it. also half way through the script I've a commented out button that I want in to interrupt the scan when pressed, could anyone point me in the right direction..? expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <Crypt.au3> #include <WinAPI.au3> ;#include <GetMAC.au3> ;not needs for this part #include <string.au3> #include <IE.au3> $errors = 0 $error_log = @ScriptDir & "\Error_logs" $tbversion = "1.0.0.0" $credsini = @scriptdir & "\toolbox.ini" $audit_book = @ScriptDir & "\Auditbook_" & @MDAY & "_" & @MON & ".csv" $error_log = @ScriptDir & "\Errorlogs\" & @MDAY & @MON & "_audit_errors.log" $localWSlist = @scriptdir & "\localWSlist.csv" $aerrors = 0 Global $objSWbemLocator, $objSWbemServices GUICreate("Sellostring ToolBox v" & $tbversion, 700, 500, -1, -1) $exit = GUICtrlCreateButton("Exit", 530, 475, 161, 25, $WS_GROUP) GUICtrlCreateTab(5,5,695, 470) ;workstation scraper _IEErrorHandlerRegister() GUICtrlCreateTabItem("Workstation scraper") GUICtrlCreateGroup("Range to Scrape", 15, 35, 400, 80) GUICtrlCreateLabel("IP Range", 20, 62, 55, 20) $ipstart = guictrlcreateinput("172.16.5.1", 75, 58, 100, 20) GUICtrlSetBkColor(-1, 0xc0c0c0) $ipend = guictrlcreateinput("172.16.5.255", 185, 58, 100, 20) GUICtrlSetBkColor(-1, 0xc0c0c0) $WSprocess = GUICtrlCreateButton("Process", 300, 58, 100, 20) $savelocal = GUICtrlCreateCheckbox("Save list local", 20, 85, 200, 20) ;$stopscrape = GUICtrlCreateButton("Stop Scrape", 150, 85, 100, 20) guictrlcreategroup("Information", 15, 120, 400, 350) $wsinfo = GUICtrlCreateEdit("", 20, 140, 385, 320, $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL) GUICtrlSetBkColor(-1, 0xc0c0c0) guictrlcreategroup("Workstations Found", 420, 35, 250, 435) $wsfound = GUICtrlCreateEdit("", 425, 52, 235, 410, $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL) GUICtrlSetBkColor(-1, 0xc0c0c0) GUICtrlCreateTabItem("") ;Settings tab Guictrlcreatetabitem("Settings") ;admin credentials GUICtrlCreateGroup("Credential", 15, 30, 380, 130) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") GUICtrlCreateLabel("Username:", 20, 52, 80, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $admin = GUICtrlCreateInput(@UserName, 112, 48, 273, 21) GUICtrlSetBkColor(-1, 0xc0c0c0) GUICtrlCreateLabel("Password:", 20, 72, 80, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $pass = GUICtrlCreateInput("", 112, 68, 273, 21, $ES_PASSWORD) GUICtrlSetBkColor(-1, 0xc0c0c0) GUICtrlCreateLabel("Domain:", 20, 92, 80, 17) GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif") $Domain = GUICtrlCreateInput("", 112, 88, 273, 21) GUICtrlSetBkColor(-1, 0xc0c0c0) ;buttons $savecreds = GUICtrlCreateButton("Save Credentials", 20, 118, 100, 25) $delcreds = GUICtrlCreateButton("Delete Saved Credentials", 130, 118, 150, 25) guictrlcreatetabitem("") if FileExists($credsini) Then ;read the credentials in the ini files $un = iniread($credsini, "Credentials" , "Username", "") $pw = iniread($credsini, "Credentials" , "Password", "") $dn = iniread($credsini, "Credentials" , "Domain", "") ;decrypt the data _Crypt_Startup() $mac = _getmac() $ckey = _Crypt_DeriveKey($mac,$CALG_DES) $dun = _Crypt_DecryptData(binary($un), $ckey, $CALG_USERKEY) $dpw = _Crypt_DecryptData(Binary($pw), $ckey, $CALG_USERKEY) $ddn = _Crypt_DecryptData(Binary($dn), $ckey, $CALG_USERKEY) _crypt_shutdown() ;put the decrypted data into the relevant boxes guictrlsetdata($admin, BinaryToString($dun), "") guictrlsetdata($pass, BinaryToString($dpw), "") guictrlsetdata($domain, BinaryToString($ddn), "") endif GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;MsgBox(64, "Thank you", "Thanks for using Sellostring ToolBox V" & $tbversion & " , written by Richard Easton 2011.", 5) Exit Case $exit ;MsgBox(64, "Thank you", "Thanks for using Sellostring ToolBox V" & $tbversion & " , written by Richard Easton 2011.", 5) Exit case $WSprocess $SL = guictrlread($savelocal) if $SL = 1 and fileexists($localWSlist) Then FileDelete(@ScriptDir & "\LocalWSlist.old") FileCopy($localWSlist, @ScriptDir & "\LocalWSlist.old") FileDelete($localWSlist) EndIf $sip = stringsplit(guictrlread($ipstart), ".") $eip = stringsplit(guictrlread($ipend), ".") ;end IP si greater the Start IP if $eip[1] < $sip[1] Then msgbox(48, "Warning!", "There is an error with the first octet of the IP range, please check!") elseif $eip[2] < $sip[2] Then msgbox(48, "Warning!", "There is an error with the second octet of the IP range, please check!") EndIf ;assign ip octets to variables $sip1 = $sip[1] $sip2 = $sip[2] $sip3 = $sip[3] $sip4 = $sip[4] $eip1 = $eip[1] $eip2 = $eip[2] $eip3 = $eip[3] $eip4 = $eip[4] ;write headers to consoles guictrlsetdata($wsinfo, "Started IP Scrape" & @CRLF, "") guictrlsetdata($wsinfo, "=================" & @CRLF, $wsinfo) guictrlsetdata($wsfound, "Workstation Name" & @CRLF, "") do $var = ping($sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4, 50) if $var Then $objSWbemLocator = ObjCreate("WbemScripting.SWbemLocator") If Not IsObj($objSWbemLocator) or @error Then ;checks to see if RPC server is available Guictrlsetdata($wsinfo, $sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4 & " " & $IEComErrorWinDescription & @CRLF, $wsinfo) Else ;if RPC is Available, connect to workstation and retrieve it's name $objSWbemServices = $objSWbemLocator.ConnectServer($sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4, "root\cimv2", GUICtrlRead($Domain) & "\" & GUICtrlRead($admin), GUICtrlRead($pass)) If @error then Guictrlsetdata($wsinfo, $sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4 & " " & $IEComErrorWinDescription & @CRLF, $wsinfo) elseif IsObj($objSWbemServices) and not @error Then $objSWbemServices.Security_.ImpersonationLevel = 3 $colItems = $objSWbemServices.ExecQuery("select * from Win32_ComputerSystem") If IsObj($colItems) Then For $objItem In $colItems $Name = $objItem.name Next EndIf ;write name to console, and if required save to local .csv guictrlsetdata($wsfound, $name & @CRLF, $wsfound) guictrlsetdata($wsinfo, "Workstation Found at " & $sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4 & @CRLF, $wsinfo) if $sl = 1 Then filewriteline($localWSlist, $name & @CRLF) EndIf EndIf EndIf Else ;if not responding to ping write to console guictrlsetdata($wsinfo, $sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4 & " is not responding to a ping request" & @CRLF, $wsinfo) sleep(100) EndIf ;increases IP octet 4 by 1 $sip4 = $sip4 +1 ;if octet 4 = 255 then increase octet 3 by 1 and set octet 4 to 1 if $sip4 = 255 Then $sip3 = $sip3 + 1 $sip4 = 1 EndIf ;continue until start ip octet 3 & 4 = end octet 3 & 4 Until $sip3 = $eip3 and $sip4 = $eip4 +1 msgbox(64, "Infomation", "range scan completed") CASE $savecreds IF guictrlread($admin) = "" or guictrlread($pass) = "" or guictrlread($Domain) = "" Then msgbox(48, "Warning!", "One of your credentials is missing, please check and correct them.", 5) Else _Crypt_Startup() $stepping = 14.3 progresson("Saving Settings", "Please wait, Encrypting Credentials", "Please Wait", -1 , -1, $pbs_smooth) $c = "apassword" ProgressSet($stepping, "Please wait, Encrypting Credentials", "Saving Settings") $ckey = _Crypt_DeriveKey($c,$CALG_DES) ProgressSet($stepping * 2, "Please wait, Encrypting Credentials", "Saving Settings") iniwrite($credsini, "Credentials", "Username", _Crypt_EncryptData(guictrlread($admin), $ckey, $CALG_USERKEY)) ProgressSet($stepping * 3, "Please wait, Encrypting Credentials", "Saving Settings") iniwrite($credsini, "Credentials", "Password", _Crypt_EncryptData(guictrlread($pass), $ckey, $CALG_USERKEY)) ProgressSet($stepping * 4, "Please wait, Encrypting Credentials", "Saving Settings") iniwrite($credsini, "Credentials", "Domain", _Crypt_EncryptData(guictrlread($Domain), $ckey, $CALG_USERKEY)) ProgressSet($stepping * 5, "Please wait, Encrypting Credentials", "Saving Settings") _Crypt_DestroyKey($ckey) ProgressSet($stepping * 6, "Please wait, Encrypting Credentials", "Saving Settings") _crypt_shutdown() ProgressSet($stepping * 7, "Please wait, Encrypting Credentials", "Saving Settings") sleep(100) ProgressSet(100, "Credentials Encrypted", "Save Successful!") sleep(1000) ProgressOff() EndIf CASE $delcreds if FileExists($credsini) Then FileRecycle($credsini) msgbox(64,"Information", "Settings deleted!", 5) EndIf EndSwitch WEnd it's part of a bigger application, which I'm working on so any help would be appreciated regards RichE Edited June 15, 2011 by l15ard RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 15, 2011 Moderators Share Posted June 15, 2011 l15ard,I had to make a few changes to get the range scan to work correctly.The major problem was that the Do...Until loop was not recognising the end of the range - a change to a While...Wend loop and a small adjustment to the logic fixed that. Next, you create strings when you use StringSplit and you want to use numbers when you do the "increase by one" calculations - using Number on the elements returned from StringSplit prevents any problem here. As you can see from this simplified version, it now scans all the IPs between 5.1 and 9.255 without problem (look for the <<<<<<<<< lines to see the changes):expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <File.au3> #include <Crypt.au3> #include <WinAPI.au3> ;#include <GetMAC.au3> ;not needs for this part #include <string.au3> #include <IE.au3> $errors = 0 $error_log = @ScriptDir & "\Error_logs" $tbversion = "1.0.0.0" $credsini = @ScriptDir & "\toolbox.ini" $audit_book = @ScriptDir & "\Auditbook_" & @MDAY & "_" & @MON & ".csv" $error_log = @ScriptDir & "\Errorlogs\" & @MDAY & @MON & "_audit_errors.log" $localWSlist = @ScriptDir & "\localWSlist.csv" $aerrors = 0 Global $objSWbemLocator, $objSWbemServices GUICreate("Sellostring ToolBox v" & $tbversion, 700, 500, -1, -1) $exit = GUICtrlCreateButton("Exit", 530, 475, 161, 25, $WS_GROUP) GUICtrlCreateTab(5, 5, 695, 470) ;workstation scraper GUICtrlCreateTabItem("Workstation scraper") GUICtrlCreateGroup("Range to Scrape", 15, 35, 400, 80) GUICtrlCreateLabel("IP Range", 20, 62, 55, 20) $ipstart = GUICtrlCreateInput("172.16.5.1", 75, 58, 100, 20) GUICtrlSetBkColor(-1, 0xc0c0c0) $ipend = GUICtrlCreateInput("172.16.9.255", 185, 58, 100, 20) GUICtrlSetBkColor(-1, 0xc0c0c0) $WSprocess = GUICtrlCreateButton("Process", 300, 58, 100, 20) $savelocal = GUICtrlCreateCheckbox("Save list local", 20, 85, 200, 20) $stopscrape = GUICtrlCreateButton("Stop Scrape", 150, 85, 100, 20) GUICtrlCreateGroup("Information", 15, 120, 400, 350) $wsinfo = GUICtrlCreateEdit("", 20, 140, 385, 320, $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL) GUICtrlSetBkColor(-1, 0xc0c0c0) GUICtrlCreateGroup("Workstations Found", 420, 35, 250, 435) $wsfound = GUICtrlCreateEdit("", 425, 52, 235, 410, $ES_MULTILINE + $WS_VSCROLL + $ES_AUTOVSCROLL) GUICtrlSetBkColor(-1, 0xc0c0c0) GUICtrlCreateTabItem("") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $exit ;MsgBox(64, "Thank you", "Thanks for using Sellostring ToolBox V" & $tbversion & " , written by Richard Easton 2011.", 5) Exit Case $WSprocess $sip = StringSplit(GUICtrlRead($ipstart), ".") $eip = StringSplit(GUICtrlRead($ipend), ".") ;assign ip octets to variables $sip1 = Number($sip[1]) $sip2 = Number($sip[2]) $sip3 = Number($sip[3]) $sip4 = Number($sip[4]) $eip1 = Number($eip[1]) $eip2 = Number($eip[2]) $eip3 = Number($eip[3]) $eip4 = Number($eip[4]) ;write headers to consoles While $sip3 <= $eip3 And $sip4 <= $eip4 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite($sip1 & "." & $sip2 & "." & $sip3 & "." & $sip4 & @CRLF) ;increases IP octet 4 by 1 $sip4 = $sip4 + 1 ;if octet 4 = 256 then increase octet 3 by 1 and set octet 4 to 1 If $sip4 = 256 Then ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $sip3 = $sip3 + 1 $sip4 = 1 EndIf WEnd MsgBox(64, "Infomation", "range scan completed") EndSwitch WEndAs to interrupting the "process" code, you have run into one of the major problems with AutoIt - it is not multi-threaded and so you cannot simply interrupt running code. But do not despair, the Interrupting a running function tutorial in the Wiki will show you a number of ways of getting around this. Have a go at integrating one of those methods into your script and come back if you run into problems. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
RichE Posted June 15, 2011 Author Share Posted June 15, 2011 Thanks Melba23, I had thought about do while.... wend as I've use that method before in other scripts. I'll dig around the help files to find the interrupt tutorials thanks again RichE RichE [font="'Arial Narrow';"]Current projects[/font] [font="'Arial Narrow';"]are on my site [/font]Sellostring 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