Solved

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

Posted on 2011-02-25
9
372 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 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

815 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now