Jump to content

Network Scanner Help


wurmz
 Share

Recommended Posts

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:

#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 by wurmz
Link to comment
Share on other sites

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?

#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

  • Developers

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

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

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.

Link to comment
Share on other sites

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

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:

#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

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 parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

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.

#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 by wurmz
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...