wurmz Posted December 29, 2012 Share Posted December 29, 2012 (edited) I'm trying to create a network scanner and I was curious, can an If statement be used to change the color of a Graphic object? This is where my mind goes for the logic, but I guess what I'm missing is creating a variable for the graphic and how to change the color of that variable after a return. Don't laugh, I'm a complete Novice, but here is my code so far: expandcollapse popup#include Opt("GUIOnEventMode", 1) $mainwindow = GUICreate( "WurmSoft Scanner", 600, 400) $scanButton = GUICtrlCreateButton( "Scan", 20, 20) $ipRange = GUICtrlCreateInput( "", 60, 20, 150) GUICtrlSetOnEvent( $scanButton, "ScanNetwork") ;Devices starts here GUICtrlCreateLabel( ".155", 20, 60) $hGraphic = GUICtrlCreateGraphic( 55, 60, 10, 10) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x666666, 0x999999) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUISetOnEvent($GUI_EVENT_CLOSE, "closeClicked") GUISetState(@SW_SHOW) Func ScanNetwork() $subnet = GUICtrlRead( $ipRange) $pingReturn = Ping( $subnet & ".155") If $pingReturn Then GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x666666, 0x00ff00) EndIf EndFunc Func closeClicked() Exit EndFunc While 1 Sleep(1000) WEnd Edited December 29, 2012 by wurmz Link to comment Share on other sites More sharing options...
wurmz Posted December 29, 2012 Author Share Posted December 29, 2012 Okay, I toyed with it some more and I've integrated something I found on the forum so ping's will look like Windows Pings. I ditched the original graphic and now I'm trying to have the If statement create a graphic, but it doesn't seem to work. The pings go through without errors, it would seem that you can't create a graphic in a function or an if statement, is that correct? expandcollapse popup#include #include Opt("GUIOnEventMode", 1) $mainwindow = GUICreate( "WurmSoft Scanner", 600, 400) $scanButton = GUICtrlCreateButton( "Scan", 20, 20) $ipRange = GUICtrlCreateInput( "", 60, 20, 150) GUICtrlSetOnEvent( $scanButton, "ScanNetwork") ;Devices starts here GUICtrlCreateLabel( ".4", 20, 60) GUISetOnEvent($GUI_EVENT_CLOSE, "closeClicked") GUISetState(@SW_SHOW) Func ScanNetwork() $subnet = GUICtrlRead( $ipRange) MsgBox( 0, @ScriptName, $subnet & ".4", -1) _PingLikeMicrosoft( $subnet & ".4") If @error Then MsgBox(0, "Ping Result", "Failed" & @CRLF & "Error code: " & @extended) Else GUICtrlCreateGraphic( 55, 60, 10, 10) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 1, 10, 10) EndIf EndFunc Func closeClicked() Exit EndFunc While 1 Sleep(1000) WEnd Link to comment Share on other sites More sharing options...
Developers Jos Posted December 29, 2012 Developers Share Posted December 29, 2012 Use these to update the graphic: GUICtrlSetGraphic($hGraphic, $GUI_GR_COLOR, 0x666666, 0x00ff00) GUICtrlSetGraphic($hGraphic, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic($hGraphic, $GUI_GR_REFRESH) Jos wurmz 1 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Xandy Posted December 29, 2012 Share Posted December 29, 2012 You can create a control within a function, but things are going to get weird if you do not free the control before creating it again. Same with the case of using an If. The idea is create, use, free. I often free with the guidelete($hgui) and not per control. You don't want to create 2 or more controls in the same place, passing back control handles to the same variable. You'd be losing handles, maybe memory, and it's just an ugly idea. You can change the background color of a graphic with guictrlsetbkcolor($hgraphic, 0x00ff00) I think let me test it all. Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
wurmz Posted December 29, 2012 Author Share Posted December 29, 2012 I love you Jos, you are my new best friend, that is exactly what I was looking for. Use these to update the graphic: GUICtrlSetGraphic($hGraphic, $GUI_GR_COLOR, 0x666666, 0x00ff00) GUICtrlSetGraphic($hGraphic, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic($hGraphic, $GUI_GR_REFRESH) Jos Link to comment Share on other sites More sharing options...
wurmz Posted December 29, 2012 Author Share Posted December 29, 2012 The next thing I'm running up against is the delay when scanning, is there any way to make the script move on instead of waiting for a response to move on between pings? Here is the code so far: expandcollapse popup#include #include Opt("GUIOnEventMode", 1) $mainwindow = GUICreate( "WurmSoft Scanner", 600, 400) $stopScan = GUICtrlCreateButton( "Stop", 20, 20) $startScan = GUICtrlCreateButton( "Scan", 60, 20) $ipRange = GUICtrlCreateInput( "", 100, 20, 150) GUICtrlSetOnEvent( $startScan, "ScanNetwork") GUICtrlSetOnEvent( $stopScan, "ScanStopped") $TO = 4000 ; Timeout Time in Miliseconds $Node1 = GUICtrlCreateGraphic( 55, 60, 10, 10) $Node2 = GUICtrlCreateGraphic( 55, 80, 10, 10) $Node3 = GUICtrlCreateGraphic( 55, 100, 10, 10) $Node4 = GUICtrlCreateGraphic( 55, 120, 10, 10) $Node5 = GUICtrlCreateGraphic( 55, 140, 10, 10) $Node6 = GUICtrlCreateGraphic( 55, 160, 10, 10) $Node7 = GUICtrlCreateGraphic( 55, 180, 10, 10) $Node8 = GUICtrlCreateGraphic( 55, 200, 10, 10) $Node9 = GUICtrlCreateGraphic( 55, 220, 10, 10) $Node10 = GUICtrlCreateGraphic( 55, 240, 10, 10) ;Devices starts here GUICtrlCreateLabel( ".1", 20, 60) GUICtrlCreateLabel( ".2", 20, 80) GUICtrlCreateLabel( ".3", 20, 100) GUICtrlCreateLabel( ".4", 20, 120) GUICtrlCreateLabel( ".5", 20, 140) GUICtrlCreateLabel( ".6", 20, 160) GUICtrlCreateLabel( ".7", 20, 180) GUICtrlCreateLabel( ".8", 20, 200) GUICtrlCreateLabel( ".9", 20, 220) GUICtrlCreateLabel( ".10", 20, 240) GUISetOnEvent($GUI_EVENT_CLOSE, "closeClicked") GUISetState(@SW_SHOW) Func ScanStopped() Exit EndFunc Func ScanNetwork() $subnet = GUICtrlRead( $ipRange) _PingLikeMicrosoft( $subnet & ".1", $TO) If @error Then GUICtrlSetGraphic( $Node1, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node1, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node1, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node1, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node1, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node1, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".2", $TO) If @error Then GUICtrlSetGraphic( $Node2, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node2, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node2, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node2, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node2, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node2, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".3", $TO) If @error Then GUICtrlSetGraphic( $Node3, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node3, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node3, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node3, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node3, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node3, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".4", $TO) If @error Then GUICtrlSetGraphic( $Node4, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node4, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node4, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node4, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node4, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node4, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".5", $TO) If @error Then GUICtrlSetGraphic( $Node5, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node5, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node5, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node5, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node5, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node5, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".6", $TO) If @error Then GUICtrlSetGraphic( $Node6, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node6, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node6, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node6, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node6, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node6, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".7", $TO) If @error Then GUICtrlSetGraphic( $Node7, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node7, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node7, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node7, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node7, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node7, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".8", $TO) If @error Then GUICtrlSetGraphic( $Node8, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node8, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node8, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node8, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node8, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node8, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".9", $TO) If @error Then GUICtrlSetGraphic( $Node9, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node9, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node9, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node9, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node9, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node9, $GUI_GR_REFRESH) EndIf _PingLikeMicrosoft( $subnet & ".10", $TO) If @error Then GUICtrlSetGraphic( $Node10, $GUI_GR_COLOR, 0x999999, 0x999999) GUICtrlSetGraphic( $Node10, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node10, $GUI_GR_REFRESH) Else GUICtrlSetGraphic( $Node10, $GUI_GR_COLOR, 0x999999, 0x00ff00) GUICtrlSetGraphic( $Node10, $GUI_GR_ELLIPSE, 0, 1, 10, 10) GUICtrlSetGraphic( $Node10, $GUI_GR_REFRESH) EndIf EndFunc Func closeClicked() Exit EndFunc While 1 Sleep(1000) WEnd Link to comment Share on other sites More sharing options...
wurmz Posted December 30, 2012 Author Share Posted December 30, 2012 Well, I've been digging around and looking at other network scanners written in AutoIT, I've realized I will never get what I'm looking for off of this base. Link to comment Share on other sites More sharing options...
guinness Posted December 30, 2012 Share Posted December 30, 2012 I've seen quite a few around the Forum. There is one by UEZ which comes to mind, you just have to find it first. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
wurmz Posted December 30, 2012 Author Share Posted December 30, 2012 (edited) I dug back in and learned the basics of how to use a While loop and cut my basic code in almost a 4th and made it much easier to scale: It's still way to slow to be usable though. expandcollapse popup#include #include Opt("GUIOnEventMode", 1) GUICreate( "test") GUISetState( @SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "closeClicked") $subnet = "192.168.1." Local $i = 0 Local $h = 0 While $i <= 100 And $h <= 1500 $ipaddress = $subnet & $i GUICtrlCreateLabel( $subnet & $i, 5, $h) $node = GUICtrlCreateGraphic( 150, $h, 10, 13) _PingLikeMicrosoft( $ipaddress, 1000) If @error Then GUICtrlSetColor( $node, 0x999999) Else GUICtrlSetColor( $node, 0x00ff00) EndIf $h = $h + 15 $i = $i + 1 WEnd Func closeClicked() Exit EndFunc While 1 Sleep( 1000) WEnd Edited December 30, 2012 by wurmz Link to comment Share on other sites More sharing options...
UEZ Posted December 30, 2012 Share Posted December 30, 2012 Might be helpful for you: Br, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ 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