Page 1 of 2 12>
Topic Options
#42977 - 2003-07-17 03:09 PM A little guidance.
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#42979 - 2003-07-17 03:20 PM Re: A little guidance.
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 Offline
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
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#42981 - 2003-07-17 03:24 PM Re: A little guidance.
maciep Offline
Korg Regular
*****

Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
Try putting the IP address in quotes

code:
$p=wshping('*.*.*.*',2)

_________________________
Eric

Top
#42982 - 2003-07-17 03:24 PM Re: A little guidance.
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
http://www.kixtart.org/board/ultimatebb.php?ubb=get_topic;f=10;t=000039
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42983 - 2003-07-17 03:43 PM Re: A little guidance.
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
#42984 - 2003-07-17 03:52 PM Re: A little guidance.
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
WSH dependant ?

ummm, there is also a ping() udf available on UDF library which 'only' s(h)ells out a bit.

Your choice anyway
_________________________



Top
#42985 - 2003-07-17 03:53 PM Re: A little guidance.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
sure.
just use Ping() - checks for reply , or returns ip-address of remote host
_________________________
!

download KiXnet

Top
#42986 - 2003-07-17 03:54 PM Re: A little guidance.
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Oh nice ... now that I saw your last reply :

ping()
_________________________



Top
#42987 - 2003-07-17 04:03 PM Re: A little guidance.
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here's a ping connectivity monitor
Top
#42988 - 2003-07-17 04:33 PM Re: A little guidance.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jochen, wonder what you did see [Razz]
_________________________
!

download KiXnet

Top
#42989 - 2003-07-17 08:57 PM Re: A little guidance.
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
#42990 - 2003-07-17 09:00 PM Re: A little guidance.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Topic: How to use UDFs
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#42991 - 2003-07-17 09:00 PM Re: A little guidance.
Howard Bullock Offline
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?
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#42992 - 2003-07-17 11:46 PM Re: A little guidance.
Bryce Offline
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.... [Big Grin]

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
#42993 - 2003-07-18 12:17 AM Re: A little guidance.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
jural, I must wonder.
you first say that you can't use WSH and then you use it?
now how is it?
_________________________
!

download KiXnet

Top
#42994 - 2003-07-18 01:58 AM Re: A little guidance.
kholm Offline
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 Offline
Korg Regular
*****

Registered: 2000-06-19
Posts: 714
Loc: Randers, Denmark
Bryce,

You dont step on my toes [Wink]

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 Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Jlo,

I did saw Jurals last reply before mine (not yours)

Bryce,

You don't step on my toes brother, you rip my heart out [Big Grin]
No, seriously, the KISS principle is still valid and for just checking the reply it fits perfectly, (It's just the way I did the check in my ping() UDF [Roll Eyes] ) ...
The only reason why I posted mine (long time ago) as is, was only the enhancement of exctracting IP from name which I still use to prepare and maintaining my Servers input ini-file for admin scripts [Wink]
_________________________



Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.17 seconds in which 0.09 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org