Discussion:
Ping Remote Host and Launch Script if Fails
(too old to reply)
K
2009-10-28 08:46:03 UTC
Permalink
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.
Pegasus [MVP]
2009-10-28 10:52:59 UTC
Permalink
Post by K
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.
Richard Mueller [MVP]
2009-10-28 16:12:27 UTC
Permalink
Post by K
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
--
Richard Mueller [MVP]
2009-10-28 16:12:27 UTC
Permalink
Post by K
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
--
Pegasus [MVP]
2009-10-28 10:52:59 UTC
Permalink
Post by K
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.

Loading...