Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Scripting > Ping Remote Host and Launch Script if Fails

Reply
Thread Tools Display Modes

Ping Remote Host and Launch Script if Fails

 
 
K
Guest
Posts: n/a

 
      10-28-2009

Is it possible to script a ping or similar to check if a remote host
responds and if it doesn't then launch a second script to perform certain
actions?

Alternatively, can the public IP (the one on the outside of my NAT) be
checked and if it's one IP do A but if it's another do B?

We have 2 internet feeds with twodifferent suppliers and hardware that
switches them over. Each has a different set of IP addresses and we need to
run some commands when it switches over, however we don't know if has
switched until it fails, an dwhen this happens out of hours it can cause
problems.


 
Reply With Quote
 
 
 
 
Pegasus [MVP]
Guest
Posts: n/a

 
      10-28-2009

"K" <> wrote in message
news:...
> Is it possible to script a ping or similar to check if a remote host
> responds and if it doesn't then launch a second script to perform certain
> actions?
>
> Alternatively, can the public IP (the one on the outside of my NAT) be
> checked and if it's one IP do A but if it's another do B?
>
> We have 2 internet feeds with twodifferent suppliers and hardware that
> switches them over. Each has a different set of IP addresses and we need
> to run some commands when it switches over, however we don't know if has
> switched until it fails, an dwhen this happens out of hours it can cause
> problems.


Here you go:
@echo off
ping PCx | find /i "bytes=" && goto :eof
rem Your commands go here

To check your external IP:
@echo off
pushd "%temp%"
if exist n09230945.asp del n09230945.asp
d:\tools\wget www.whatismyip.com/automation/n09230945.asp -onul
for /F %%a in (n09230945.asp) do set ExternalIP=%%a
if exist n09230945.asp del n09230945.asp
popd
echo Your external IP is %ExternalIP%

This batch file needs d:\Tools\wget.exe which you can download from
http://users.ugent.be/~bpuype/wget/#download.


 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      10-28-2009

"K" <> wrote in message
news:...
> Is it possible to script a ping or similar to check if a remote host
> responds and if it doesn't then launch a second script to perform certain
> actions?
>
> Alternatively, can the public IP (the one on the outside of my NAT) be
> checked and if it's one IP do A but if it's another do B?
>
> We have 2 internet feeds with twodifferent suppliers and hardware that
> switches them over. Each has a different set of IP addresses and we need
> to run some commands when it switches over, however we don't know if has
> switched until it fails, an dwhen this happens out of hours it can cause
> problems.
>


Example VBScript ping functions:

http://www.rlmueller.net/PingComputers.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59