Jump to content

Ping and exit to second loop


 Share

Recommended Posts

Hi

i have little problem using ping function here is script im working on it if $var=0 not works for me donno y and tell if i disable lan then how to successfully exitloop in function _monitor

While 1
sleep(100)
$var = Ping('192.168.0.42' ,250)
If $var = 1 Then call('_monitor')
WEnd
    
    
Func _monitor()
While 1
sleep(10)
If $var = 0 Then ExitLoop
Msgbox(0,"Status","ip online")
WEnd
EndFunc
Link to comment
Share on other sites

While 1
sleep(100)
$var = Ping('192.168.0.42' ,250)
If $var = 1 Then call('_monitor')
WEnd    
    
Func _monitor()
While 1
sleep(10)
If $var = 0 Then ExitLoop
Msgbox(0,"Status","ip online")
WEnd
EndFunc
At the top of your script add

Global $var

Link to comment
Share on other sites

  • Developers

Hi

i have little problem using ping function here is script im working on it if $var=0 not works for me donno y and tell if i disable lan then how to successfully exitloop in function _monitor

While 1
sleep(100)
$var = Ping('192.168.0.42' ,250)
If $var = 1 Then call('_monitor')
WEnd
    
    
Func _monitor()
While 1
sleep(10)
If $var = 0 Then ExitLoop
Msgbox(0,"Status","ip online")
WEnd
EndFunc
You are NOT updating $var in the _Monitor func. so you created an endless loop

At the top of your script add

Global $var

Is the same as the original script.. When the Variable is Set in the main of the script it will have a Global scope. Edited by JdeB

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

i have little problem using ping function here is script im working on it if $var=0 not works for me donno y and tell if i disable lan then how to successfully exitloop in function _monitor

While 1
sleep(100)
$var = Ping('192.168.0.42' ,250)
If $var = 1 Then call('_monitor')
WEnd
    
    
Func _monitor()
While 1
sleep(10)
If $var = 0 Then ExitLoop
Msgbox(0,"Status","ip online")
WEnd
EndFunc

Yeah what JdeB said.

; I'm here because $var = 1

Func _monitor()

While 1

sleep(10)

; $var never = 0

If $var = 0 Then ExitLoop

Msgbox(0,"Status","ip online")

WEnd

EndFunc

Link to comment
Share on other sites

this code works but take to much bandwidth while checking ping any better soultion will be appreciated

While 1
sleep(100)
$var = Ping('192.168.0.42' ,250)
If $var = 1 Then call('_monitor')
WEnd
    
    
Func _monitor()
While 1
sleep(10)
$var = Ping('192.168.0.42' ,250)
If @error Then ExitLoop
Msgbox(0,"Status","ip online")
WEnd
EndFunc
Link to comment
Share on other sites

  • Developers

this code works but take to much bandwidth while checking ping any better soultion will be appreciated

Maybe you can first tell us what you want to do here... I am lost why you have the Unsuccessful Ping call the _Monitor func.....

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

im trying to detect internet connection if internet is detected it show ip is online otherwise Continue first loop if u guyz have better way to detect internet connection then share with me

While 1
    If Not _NetCheck()Then
        MsgBox(0,"Status","We have a network connection",5)
        ExitLoop
    EndIf
    Sleep(10000);wait 10 seconds and try again
WEnd


Func _NetCheck()
    Ping('192.168.0.42' ,250)   ; 192.168.0.1
    return @error
EndFunc
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...