BinaryBrother Posted Tuesday at 08:21 PM Posted Tuesday at 08:21 PM (edited) Attempting to Run [F5] this script, the console tells me that a referenced Global Variable $bGet_ARP_Table_FirstRun at line 88 isn't declared. Yet it clearly is declared, as Global, on line 9. expandcollapse popup#include <MsgBoxConstants.au3> #include <Array.au3> Global $sDatabase_Path = @ScriptDir & "\NetworkMonitor.ini" Global $sIP = _GetGatewayIP() Global $aIP = StringSplit($sIP, ".") Global $aARP_Table = _Get_ARP_Table() Global $bFill_ARP_Table_FirstRun = True Global $bGet_ARP_Table_FirstRun = True $aARP_Table = _Get_ARP_Table() _ArrayDisplay($aARP_Table) $aData = IniReadSection($sDatabase_Path, "Monitor") While 1 For $N = 1 To $aData[0][0] ;$aData[$N][0] = MAC Address ;$aData[$N][1] = User $lReturn = _PingMAC($aData[$N][0]) If @error Or $lReturn = False Then ConsoleWrite("WARNING: Unable to communicate with " & $aData[$N][1] & @CRLF) _Tracker($aData[$N][0], "DOWN") ;MsgBox($MB_OK, "Network Snitch", $aData[$N][1] & " left the network!") Else _Tracker($aData[$N][0], "UP") EndIf Sleep(500) Next WEnd Func _GetReturn($sCommand) Local $lReturn = Run(@ComSpec & " /c " & $sCommand, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $lOutput = "" While 1 $lOutput &= StdoutRead($lReturn) If @error Then ExitLoop $lOutput &= StderrRead("ERROR:" & $lReturn) WEnd Return $lOutput EndFunc ;==>_GetReturn Func _GetActiveIP() Local $aIP_Address[5] $aIP_Address[1] = @IPAddress1 $aIP_Address[2] = @IPAddress2 $aIP_Address[3] = @IPAddress3 $aIP_Address[4] = @IPAddress4 For $N = 1 To 4 $lReturn = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION, "Network Snitch", "Is this your proper network IP?" & @CRLF & $aIP_Address[$N]) If $lReturn = $IDYES Then Return $aIP_Address[$N] EndIf Next EndFunc ;==>_GetActiveIP Func _GetGatewayIP() Local $lReturn = _GetReturn("tracert -d -h 1 -4 8.8.8.8") Local $aIPs = StringRegExp($lReturn, "(\d+\.\d+\.\d+\.\d+)", 3) Return $aIPs[1] EndFunc ;==>_GetGatewayIP Func _Fill_ARP_Table() ; This function will scan the network for devices and add them to the ARP Table Local $lIP Local $lProgress If $bFill_ARP_Table_FirstRun Then SplashTextOn("Network Snitch", "Scanning Network...", 300, 100, -1, -1, 1, "", 14) For $N = 1 To 255 $lIP = $aIP[1] & "." & $aIP[2] & "." & $aIP[3] & "." & $N ConsoleWrite("Pinging: " & $lIP & @CRLF) Run(@ComSpec & " /c ping -n 5 -w 2000 " & $lIP, "", @SW_HIDE) If $bFill_ARP_Table_FirstRun Then $lProgress = Round(($N / 255) * 100, 2) If $bFill_ARP_Table_FirstRun Then ControlSetText("Network Snitch", "", "Static1", "Scanning Network..." & @CRLF & "Progress: " & $lProgress & "%") Sleep(50) Next If $bFill_ARP_Table_FirstRun Then SplashOff() $bFill_ARP_Table_FirstRun = False EndFunc ;==>_Fill_ARP_Table Func _Get_ARP_Table() If $bGet_ARP_Table_FirstRun Then _Fill_ARP_Table() Local $lReturn = _GetReturn("arp -a") $lReturn = StringSplit($lReturn, @CRLF, 1) $bGet_ARP_Table_FirstRun = False Return $lReturn EndFunc ;==>_GetARPTable Func _PingIP($pIP) Local $iFailCount = 0 Local $lReturn For $N = 1 To 4 $lReturn = Ping($pIP, 2000) If Not @error And $lReturn >= 1 Then ContinueLoop Else $iFailCount += 1 EndIf Sleep(500) Next If $iFailCount >= 0 Then Return SetError($iFailCount, 0, False) Else Return True EndIf EndFunc ;==>_PingIP Func _Tracker($sMAC, $sStatus) IniWrite($sDatabase_Path, "Tracker", $sMAC, $sStatus) ; Add additional tracking logic here if needed EndFunc ;==>_Tracker Func _PingMAC($sMAC) ConsoleWrite("_PingMAC(): " & $sMAC & @CRLF) Local $aMonitor = IniReadSection($sDatabase_Path, "Entry") For $N = 1 To $aMonitor[0][0] If StringInStr($aMonitor[$N][1], $sMAC) Then ConsoleWrite("_PingMAC(): Found IP in DB " & $aMonitor[$N][0] & @CRLF) $lReturn = _PingIP($aMonitor[$N][0]) If Not @error Then ConsoleWrite("_PingMAC(): " & $aMonitor[$N][0] & " is UP!" & @CRLF) Return True Else ConsoleWrite("_PingMAC(): " & $aMonitor[$N][0] & " is DOWN!" & @CRLF) Return False EndIf EndIf Next EndFunc ;==>_PingMAC Console: >Running:(3.3.16.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "d:\Dropbox\Projects\NetworkMonitor\AutoIt\NetworkMonitor.au3" /errorstdout +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart. --> Press Ctrl+BREAK to Stop. "d:\Dropbox\Projects\NetworkMonitor\AutoIt\NetworkMonitor.au3" (82) : ==> Variable used without being declared.: If $bGet_ARP_Table_FirstRun Then _Fill_ARP_Table() If ^ ERROR > ->14:15:20 AutoIt3 ended. rc:1 +>14:15:21 AutoIt3Wrapper Finished. ->Exit code 1 Time: 1.652 I tried both in @Jos's ScITE Beta, and VSCode. I am seriously confused. I think it's one of those things where there's an error somewhere else that's causing this. Edited Tuesday at 08:22 PM by BinaryBrother SIGNATURE_0X800007D NOT FOUND
Solution argumentum Posted Tuesday at 08:37 PM Solution Posted Tuesday at 08:37 PM 14 minutes ago, BinaryBrother said: I am seriously confused. Global $bFill_ARP_Table_FirstRun = True; <==== Global $bGet_ARP_Table_FirstRun = True ; <==== Global $sDatabase_Path = @ScriptDir & "\NetworkMonitor.ini" Global $sIP = _GetGatewayIP() Global $aIP = StringSplit($sIP, ".") Global $aARP_Table = _Get_ARP_Table() Musashi 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
BinaryBrother Posted Tuesday at 08:40 PM Author Posted Tuesday at 08:40 PM Ugh, what a rookie thing to miss. Thanks @argumentum argumentum 1 SIGNATURE_0X800007D NOT FOUND
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