ttleser Posted December 16, 2006 Posted December 16, 2006 I need to write a program that'll monitor a VPN connection. I'm having a problem with the logic, cause I can't seem to get it to loop properly. It should continually ping the VPN computer until it can't, then ping the Internet. Either way it needs to report the results to the same window. I've been playing with it a while, so don't be surprised if you see something that doesn't make sense. Here's the code: expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> GUICreate("Connection Monitor", 400, 400) GUISetIcon("SHELL32.dll", 18) $font="Arial Black" $font1="Arial" ; Show the GUI $status = "VPN Connected" GUISetState() GUISetFont (18, 400, 0, $font) GuiCtrlCreateLabel("Status", 25, 50,) GUISetFont (9, 400, 0, $font1) $button_exit = GUICtrlCreateButton('E&xit', 90, 330, 75, 23) While 1 $msg = GUIGetMsg() Select Case $msg = $button_exit Exit Case $msg = $GUI_EVENT_CLOSE Exit Case $msg = "" Do $var = Ping("192.168.1.1", 250) If $var = 0 Then GUISetFont (18, 400, 0, $font) GuiCtrlCreateLabel("VPN Down", 140, 50,) GuiCtrlSetBkColor(-1, 0xFF0000) EndIF $var1 = Ping("www.yahoo.com", 250) If $var1 = 0 Then GUISetFont (18, 400, 0, $font) GuiCtrlCreateLabel("Internet Down", 140, 50,) GuiCtrlSetBkColor(-1, 0xFF0000) EndIf Until $msg = $button_exit EndSelect WEnd
sheck Posted December 16, 2006 Posted December 16, 2006 expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> GUICreate("Connection Monitor", 400, 400) GUISetIcon("SHELL32.dll", 18) $font = "Arial Black" $font1 = "Arial" ; Show the GUI $status = "VPN Connected" GUISetState() GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Status", 25, 50,) GUISetFont(9, 400, 0, $font1) $button_exit = GUICtrlCreateButton('E&xit', 90, 330, 75, 23) While 1 $msg = GUIGetMsg() Select Case $msg = $button_exit Exit Case $msg = $GUI_EVENT_CLOSE Exit EndSelect $var = Ping("192.168.1.1", 250) If $var = 0 Then GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("VPN Down", 140, 50,) GUICtrlSetBkColor(-1, 0xFF0000) EndIf $var1 = Ping("www.yahoo.com", 250) If $var1 = 0 Then GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Internet Down", 140, 50,) GUICtrlSetBkColor(-1, 0xFF0000) EndIf Sleep(10000) WEnd This should work for pinging. One thing I noticed is odd though. You're pinging IP address first, but that computer will be pingable regardless of whether VPN is connected or not as long as it allows ping requests. Live and Learn, 'cause Knowledge is Super Power.
ttleser Posted December 16, 2006 Author Posted December 16, 2006 Copy/Pasted that code and it didn't work. Here's that didn't work. 1. GUI didn't update with current status. 2. Couldn't click the exit button, had to close it via the script icon in the tray. To answer your questions: You're pinging IP address first, but that computer will be pingable regardless of whether VPN is connected or not as long as it allows ping requests.Actually 192.168.1.1 isn't on the current network, it's across the VPN connection. The current network is 192.168.3.x If $var1 = 0 Then GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Internet Down", 140, 50,) GUICtrlSetBkColor(-1, 0xFF0000) EndIf Sleep(10000) What do you have the sleep command in here for?
sheck Posted December 16, 2006 Posted December 16, 2006 (edited) Copy/Pasted that code and it didn't work. Here's that didn't work. 1. GUI didn't update with current status. 2. Couldn't click the exit button, had to close it via the script icon in the tray. To answer your questions: Actually 192.168.1.1 isn't on the current network, it's across the VPN connection. The current network is 192.168.3.x If $var1 = 0 Then GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Internet Down", 140, 50,) GUICtrlSetBkColor(-1, 0xFF0000) EndIf Sleep(10000) What do you have the sleep command in here for?Sorry, I don't know why I put sleep in there, LOL Also I fixed some errors u had, mostly improper coordinates. expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> GUICreate("Connection Monitor", 400, 400) ;GUISetIcon("SHELL32.dll", 18) $font = "Arial Black" $font1 = "Arial" ; Show the GUI $status = "VPN Connected" GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Status", 25, 50, 100, 60) GUISetFont(9, 400, 0, $font1) $button_exit = GUICtrlCreateButton('E&xit', 90, 330, 75, 23) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $button_exit Exit Case $msg = $GUI_EVENT_CLOSE Exit EndSelect $var = Ping("192.168.1.1", 32) If $var = 0 Then GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("VPN Down", 140, 50, 160, 40) GUICtrlSetBkColor(-1, 0xFF0000) EndIf $var1 = Ping("www.yahoo.com", 32) If $var1 = 0 Then GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Internet Down", 140, 50, 160, 40) GUICtrlSetBkColor(-1, 0xFF0000) EndIf WEnd Edited December 16, 2006 by sheckandar Live and Learn, 'cause Knowledge is Super Power.
MHz Posted December 16, 2006 Posted December 16, 2006 If you want the Gui to be responsive then remove the Sleep and use Time* functions. example $time = TimerInit() While 1 If TimerDiff($time) > 10000 Then $time = TimerInit() ;ping() every 10 seconds ConsoleWrite('ping' & @CRLF) EndIf WEnd You may need a visual alert while the Ping function is operating as the loop would be pause while it is pinging.
ttleser Posted December 17, 2006 Author Posted December 17, 2006 Alrighty. Thanks for the reply. I got the script working a little further and added a couple more things. Here's what I'm having problems with: 1. Window doesn't always close when I tell it to. 2. I need the time when the VPN Connect FIRST went down, not what the current time is. 3. I need the time when the Internet FIRST went down, not what the current time is. I'd like to add a couple more time fields, like when the VPN connection and Internet Connection came back up. Any thoughts on how to do any of this? expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> #include<date.au3> Global $Sec, $Min, $Hour, $Time GUICreate("Connection Monitor", 400, 400) ;GUISetIcon("SHELL32.dll", 18) $font = "Arial Black" $font1 = "Arial" ; Show the GUI $vpnstatus = "Testing" $inetstatus = "Testing" GUISetFont(16, 400, 0, $font) GUICtrlCreateLabel("VPN Status", 25, 50, 190, 60) GUICtrlCreateLabel($vpnstatus, 240, 50, 90, 40) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlCreateLabel("Internet Status", 25, 100, 190, 60) GUICtrlCreateLabel($inetstatus, 240, 100, 90, 40) GUICtrlSetBkColor(-1, 0x00FF00) ;Time listings $vpndowntime = "N/A" $inetdowntime = "N/A" GUISetFont(10, 400, 0, $font1) GUICtrlCreateLabel("Last VPN Downtime", 25, 250, 190, 60) GUICtrlCreateLabel($vpndowntime, 240, 250, 90, 40) GUICtrlCreateLabel("Last Internet Downtime", 25, 270, 190, 60) GUICtrlCreateLabel($inetdowntime, 240, 270, 90, 40) GUISetFont(9, 400, 0, $font1) $button_exit = GUICtrlCreateButton('E&xit', 90, 330, 75, 23) GUISetState() While 1 $msg = GUIGetMsg() Select Case $msg = $button_exit Exit Case $msg = $GUI_EVENT_CLOSE Exit EndSelect $var = Ping("192.168.1.2", 250) If $var < 1 Then ; Msgbox (0, "test","192.168.1.2 ="&$var) GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("", 240, 50, 210, 40) Sleep (1000) GUICtrlCreateLabel("Down", 240, 50, 80, 40) GUICtrlSetBkColor(-1, 0xFF0000) Sleep (1500) GUISetFont(10, 400, 0, $font1) if @hour < "12" then $hour = 24 - @hour $ampm = "AM" Else $ampm = "PM" EndIF if @hour = 0 then $hour = 12 + @hour $ampm = "AM" Else $ampm = "PM" EndIF GUICtrlCreateLabel($hour&":"&@min&" "&$ampm, 240, 250, 90, 40) Else GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Connected", 240, 50, 150, 40) GUICtrlSetBkColor(-1, 0x00FF00) EndIf $var1 = Ping("www.yahoo.com", 250) If $var1 < 1 Then ; Msgbox (0, "test","yahoo ="&$var1) GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("", 240, 100, 210, 40) Sleep (1000) GUICtrlCreateLabel("Down", 240, 100, 80, 40) GUICtrlSetBkColor(-1, 0xFF0000) Sleep (1500) GUISetFont(10, 400, 0, $font1) if @hour < "12" then $hour = 24 - @hour $ampm = "AM" Else $ampm = "PM" EndIF if @hour = 0 then $hour = 12 + @hour $ampm = "AM" Else $ampm = "PM" EndIF GUICtrlCreateLabel($hour&":"&@min&" "&$ampm, 240, 270, 90, 40) Else GUISetFont(18, 400, 0, $font) GUICtrlCreateLabel("Connected", 240, 100, 150, 40) GUICtrlSetBkColor(-1, 0x00FF00) EndIf WEnd
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