#42977 - 2003-07-17 03:09 PM
A little guidance.
|
Anonymous
Anonymous
Unregistered
|
I need a little guidance on how to write a script that will ping a particular IP address and if no reply execute a command. If it gets a reply it will pause for a certain amount of time before pinging again. Basically I want to ping an outside interface, if no response then reboot the router. That way I won't get paged all night long ;-) I have tried searching the board but apparently can't guess the proper syntax to find any useful results. Thanks in advance for you help.
Jural
Jural
|
Top
|
|
|
|
#42978 - 2003-07-17 03:12 PM
Re: A little guidance.
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
check out the WshPing() UDF
and do something like
break on while 1 $p=wshping($ip,2) if $p[1]>0 ? 'ping successful' else ? 'ping failed' endif sleep 3 loop
|
Top
|
|
|
|
#42979 - 2003-07-17 03:20 PM
Re: A little guidance.
|
Anonymous
Anonymous
Unregistered
|
Thanks for that very fast reply. I am not familiar with UDF scripting and won't pretend to know what I'm doing. Could you please simplify for the lame. Where will I need to add the IP that I want to ping? I am getting this error.
Script error : expected expression ! $p=wshping(*.*.*.*,2)
Thanks Jural
|
Top
|
|
|
|
#42980 - 2003-07-17 03:23 PM
Re: A little guidance.
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
read the FAQ forum for all kinds of info on how to use UDFs
go into the UDF forum to find them
insert a line in my example after the break statement: $ip='192.168.110.1'
and chnage the ip to the one you need pinged
|
Top
|
|
|
|
#42982 - 2003-07-17 03:24 PM
Re: A little guidance.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
|
Top
|
|
|
|
#42983 - 2003-07-17 03:43 PM
Re: A little guidance.
|
Anonymous
Anonymous
Unregistered
|
After testing your sample, I will not be able to use WSH. Is it possilbe to do this with Kix alone? Thanks
Jural
|
Top
|
|
|
|
#42985 - 2003-07-17 03:53 PM
Re: A little guidance.
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
|
Top
|
|
|
|
#42987 - 2003-07-17 04:03 PM
Re: A little guidance.
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Here's a ping connectivity monitor
|
Top
|
|
|
|
#42989 - 2003-07-17 08:57 PM
Re: A little guidance.
|
Anonymous
Anonymous
Unregistered
|
Okay, tried the below code and get the below error. NE ideas. Thanks for all of the suggestions. Jural
code:
break on $ip="199.0.66.50" while 1 $p=wshping($ip,2) if $p[1]>0 ? 'ping successful' else ? 'ping failed' endif sleep 3 loop
Script error : expected expression ! $p=wshping($ip,2)
|
Top
|
|
|
|
#42991 - 2003-07-17 09:00 PM
Re: A little guidance.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I don't see the wshping UDF. Did you read the FAQ link I posted above?
|
Top
|
|
|
|
#42992 - 2003-07-17 11:46 PM
Re: A little guidance.
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
don't mean to go steping on any toes now, but i always feel simpler is better....
code:
$server = "kixtart.org" if ping($server) ? $server + " is alive" else ? $server + " is dead" endif
function ping($ipaddress) shell '%comspec% /c ping -n 1 $ipaddress | find /i "ttl" > nul' if @error $ping = 0 else $ping = 1 endif endfunction
|
Top
|
|
|
|
#42994 - 2003-07-18 01:58 AM
Re: A little guidance.
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
If you just want to know if the pinged IP-address/WS-Name is alive, you can use this
code:
$WS = '10.1.1.4' ; Ping by IP-address If Not adPing($WS) $WS + ' Not responding' ? EndIf $WS = 'WS04' ; Ping by name If Not adPing($WS) $WS + ' Not responding' ? EndIf Function adPing($WS) Dim $oPing,$Qry,$oStatus,$Chk
$Qry = "select * from Win32_PingStatus where address='" + $WS + "'" $oPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery($Qry) For Each $oStatus In $oPing $Chk = $oStatus.StatusCode If VarType($Chk) > 1 If $oStatus.StatusCode = 0 $adPing = 1 EndIf EndIf Next EndFunction
No temp files, and no dependencies, besides the WS you execute this from must be Win2k+ or have wmicore installed.
-Erik
|
Top
|
|
|
|
#42995 - 2003-07-18 02:28 AM
Re: A little guidance.
|
kholm
Korg Regular
   
Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
|
Bryce,
You dont step on my toes
I believe that yor solution is the simplest and most independant of OS, for the 'alive' bussiness.
-Erik
|
Top
|
|
|
|
#42996 - 2003-07-18 08:51 AM
Re: A little guidance.
|
Jochen
KiX Supporter
   
Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 1574 anonymous users online.
|
|
|