Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is there a script which can tell if a serveur respond to a ping request?

Posted on 2011-02-25
9
Medium Priority
?
375 Views
Last Modified: 2012-08-14
Is there a script which can tell if a serveur respond to a ping request? I have list of server in txt file.
0
Comment
Question by:SAM2009
9 Comments
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 136 total points
ID: 34983317
This can be done easy in powershell if you have that install.

$Servers = get-content c:\servers.txt
$Servers | %{
If (Test-connection $_ -count 1 -q){
"$($_) is UP"}
ELse{"$($_) is Down"}}
0
 
LVL 8

Assisted Solution

by:ragnarok89
ragnarok89 earned 132 total points
ID: 34983341
Not sure how you want to be notified...

Below is a PHP script I use that checks ping, and if they fail, launches blat, a free email tool, to notify me by email.

Al
$ip = "192.168.x.x";
exec("ping -w 100 $ip", $response);
$lost=strstr($response[9],"Lost");
$pos=strpos($lost,"=")+2;
$value=substr($lost,$pos);
$value = strtok($value,"(");
unset($response);
if ($value ==4) {
  $data_computername="--------------------<br>";
  $data_computername.="computername<br>";
  $data_computername.="--------------------<p>";
  $data_computername.="computername at ip $ip is down.<p>";
  $alarm_computername=1;
}
if ($alarm_computername==1){
  $data.=$data_computername;
}

$smtp = "my.exchserver.com";
$sender = "my@email.com";
$from_name = "support@email.com";
$pwd = "mypass";
$to = "recipient@email.com";

exec("r:\z_automation\blat.exe -server $smtp -u $sender -pw $pwd -t $to -s \"ALARM RAISED\" -f $from_name -html -body \"$data\" ");

Open in new window

0
 
LVL 8

Expert Comment

by:subhashchy
ID: 34983384
if you want batch script then below can be used.

@echo off & setlocal enabledelayedexpansion
for /f %%a in (list.txt) do (

ping -n 1 %%a >%temp%\pngoutput.bat 
findstr /i "TTL" %temp%\pngoutput.bat >nul
if !errorlevel!	== 0 echo Server %%a responded to ping
if !errorlevel!	== 1 echo Server %%a is not responding to ping
)

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 132 total points
ID: 34983888
Hi, there's an article here that include an example of using a Ping function:
http://www.experts-exchange.com/A_4379.html

Regards,

Rob.
0
 
LVL 1

Author Comment

by:SAM2009
ID: 34984821
Hey guys is the script that your provide can put the info in same file as teh server's file like:

server_name1 respond
server_name2  not respond
0
 
LVL 8

Assisted Solution

by:subhashchy
subhashchy earned 800 total points
ID: 34985213
yes, this will do that ..assumeing the server list is list.txt in same folder..

@echo off & setlocal enabledelayedexpansion
echo. >%temp%\output.txt
for /f %%a in (list.txt) do (

ping -n 1 %%a >%temp%\pngoutput.bat 
findstr /i "TTL" %temp%\pngoutput.bat >nul
if !errorlevel!	== 0 echo %%a respond >>%temp%\output.txt
if !errorlevel!	== 0 echo %%a responded
if !errorlevel!	== 1 echo %%a not respond >>%temp%\output.txt
if !errorlevel!	== 1 echo %%a not responded
) 
ping -n 4 4.2.2.2 >nul
type %temp%\output.txt >list.txt

Open in new window

0
 
LVL 8

Expert Comment

by:subhashchy
ID: 34985221
Let me know if you are using 2008 servers.. In that case will have to change the a little bit...instead of finding "TTL" find "reply"
0
 
LVL 7

Accepted Solution

by:
ednetman earned 800 total points
ID: 34991649
This is probably the easist way to do what you are looking for, download this free tool called pping.
http://www.intsoft.com/products/pping/instructions.php
----------------------------------------------------------------------------
Here are a few sammple command lines.
pping /include:"path to your server list"
pping /include:c:\temp\list.txt /report:all >>c:\temp\report.txt
----------------------------------------------------------------------------
It will pull in machines from a lst, and the output can ported to a text file.  It will also do IP ranges, which is very helpfull.

Basic return is:
machine is ok
  or
machine is not ok

multiple machines:
all 5 machines are ok

You can also do a more verbose report. (/report:all).
The report looks like this:

12.34.56.40 (?) is ok; RTT = 0 msec
12.34.56.41 (?) is ok; RTT = 0 msec
12.34.56.43 (?) is ok; RTT = 0 msec
12.34.56.42 (?) is ok; RTT = 0 msec
12.34.56.45 (?) is ok; RTT = 0 msec
12.34.56.44 (?) is ok; RTT = 0 msec
12.34.56.46 (?) is ok; RTT = 0 msec
12.34.56.47 (?) is ok; RTT = 0 msec
12.34.56.48 (?) is ok; RTT = 0 msec
12.34.56.49 could not be reached

#machines sent / replied / timed-out = 10 / 9 / 1
0
 
LVL 1

Author Closing Comment

by:SAM2009
ID: 34997291
Thank you for all your helps!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn about cloud computing and its benefits for small business owners.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question