Solved

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

Posted on 2011-02-25
9
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 34 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 33 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
Independent Software Vendors: 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 33 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 200 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 200 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

687 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