Ping mutiple ips .bat file - Ping Mutiple Hosts
Here is a small code snippet used for knowing the status of multiple machines/hosts/Ips status.
Say you have n number of Hosts and you want to know how many of them are reachable/pingable from your machine, it will be difficult to see the status of each machine one by one.
So we can do this using simple BAT file in windows.
We will be doing this using 2 files one is pinghosts.bat and second one is myhosts.txt
myhosts.txt : it contains the list of IPs or hostnames to be verified
Sample myhosts.txt looks like the below
9.124.113.49
9.124.113.81
9.124.112.100
9.124.112.101
9.124.113.82
9.124.113.83
pinghosts.bat >>>> It is a simple bat file to ping each and every machine specified in myhosts.txt and log the status in a log file called ping.log
sample pinghosts.bat looks like the below
#This batch file is to ping multiple hosts
#and gets the status of the machines
#(List of IPs to be checked should be specified in a file)
ping -a -n 1 %1 |findstr "Reply from" >> ping.log
echo %ERRORLEVEL%
if errorlevel==1 goto notgood
if errorlevel==0 goto good
:notgood
echo %1 is not pingable >> ping.log
goto end
:good
echo %1 is good >> ping.log
goto end
:end
echo ---------------------- >> ping.log
#end of batch
Once the pinghosts.bat and myhosts.txt are ready go to command prompt in windows and change directory to the location where pinghosts and myhosts are located.
then run the following command
for /f %z in (myhosts.txt) do pinghosts.bat %%z
Note : the ping.log will be created in the current directory where the pinghosts.bat exists.
6 comments to "Ping mutiple ips .bat file"
Post a Comment
Whoever writes Inappropriate/Vulgar comments to context, generally want to be anonymous …So I hope U r not the one like that?
For lazy logs, u can at least use Name/URL option which doesn’t even require any sign-in, The good thing is that it can accept your lovely nick name also and the URL is not mandatory too.
Thanks for your patience
~Krishna(I love "Transparency")
Popular Posts
-
The best solution to know about these init levels is to understand the " man init " command output on Unix. There are basically 8...
-
How to Unlock BSNL 3G data card to use it with Airtel and Vodafone Model no : LW272 ? How to unlock BSNL 3G data card( Model no : LW272 )us...
-
How to transfer bike registration from one State to other (Karnataka to Andhra)?? Most of us having two wheelers purchased and registered in...
-
ఓం శ్రీ స్వామియే శరణం ఆయ్యప్ప!! Related posts : Trip to Sabarimala - Part 1 Trip to Sabarimala - Part 2 Ayappa Deeksha required things...
-
Following are some of interesting blogs I found till now ...please comment to add your blog here. Blogs in English : http://nitawriter.word...
Popular posts
- Airtel and vodafone GPRS settings for pocket PC phones
- Andhra 2 America
- Ayyappa Deeksha required things
- Blogs I watch !
- Captions for your bike
- DB2 FAQs
- Deepavali Vs The Goddes of sleep
- ETV - Dhee D2 D3
- Evolution of smoking in India Women
- How to make credit card payments?
- init 0, init 1, init 2 ..
- Java-J2EE interview preparation
- mCheck Application jar or jad download
- My SQL FAQs
- My Travelogues
- Old is blod - New is italic
- Online pay methids for credit cards
- Oracle FAQs
- Pilgrimages
- Smoking in Indian Women
- Technology Vs Humans
- Twitter feeds for all Telugu stars on single page.
- Unix best practices
- Unix FAQs
Saleh says:
Suppose if you want to ping all ips in a particular domain you can use the below
Instead of manually pinging all IP addresses on your LAN you can use this nice command:
Open Command Prompt and type:
FOR /L %i IN (1,1,254) DO ping -n 1 192.168.0.%i | FIND /i "Reply">>c:\ipaddresses.txt
The "-n 1" is for only 1 ping packet to be sent to each computer.
Change 192.168.0 to match you own Network ID.
This will ping all IP addresses on the 192.168.0.0 network segment and create a text file called IPADDRESSES.TXT in C:\, where it will list only the IP addresses that gave a reply.
You can also add a -a to the PING command to resolve all the responding IP addresses to HOST names, but doing so will cause the script to take a considerable time to finish:
FOR /L %i IN (1,1,254) DO ping -a -n 1 192.168.0.%i | FIND /i "Reply">>c:\ipaddresses.txt
don't forget to type the command in 1 line.
Karthik says:
For unix - Shell script is much helpful so try below code in a shell script
#script to ping multiple hosts
#for loop
for i in cat `cat ~/ping.txt`
do
fping $i | grep unreachable
done
Anonymous says:
c:\windows\system32\etc\hosts
Unknown says:
HELLO
Below script just satfisfies the first IF condition regardless of the situation.. is there any changes to be made ??
Ping mutiple ips .bat file - Ping Mutiple Hosts
Here is a small code snippet used for knowing the status of multiple machines/hosts/Ips status.
Say you have n number of Hosts and you want to know how many of them are reachable/pingable from your machine, it will be difficult to see the status of each machine one by one.
So we can do this using simple BAT file in windows.
We will be doing this using 2 files one is pinghosts.bat and second one is myhosts.txt
myhosts.txt : it contains the list of IPs or hostnames to be verified
Sample myhosts.txt looks like the below
9.124.113.49
9.124.113.81
9.124.112.100
9.124.112.101
9.124.113.82
9.124.113.83
pinghosts.bat >>>> It is a simple bat file to ping each and every machine specified in myhosts.txt and log the status in a log file called ping.log
sample pinghosts.bat looks like the below
#This batch file is to ping multiple hosts
#and gets the status of the machines
#(List of IPs to be checked should be specified in a file)
ping -a -n 1 %1 |findstr "Reply from" >> ping.log
echo %ERRORLEVEL%
if errorlevel==1 goto notgood
if errorlevel==0 goto good
:notgood
echo %1 is not pingable >> ping.log
goto end
:good
echo %1 is good >> ping.log
goto end
:end
echo ---------------------- >> ping.log
#end of batch
Once the pinghosts.bat and myhosts.txt are ready go to command prompt in windows and change directory to the location where pinghosts and myhosts are located.
then run the following command
for /f %z in (myhosts.txt) do pinghosts.bat %%z
Note : the ping.log will be created in the current directory where the pinghosts.bat exists
Stuart says:
In the code for /f %z in (myhosts.txt) do pinghosts.bat %%z
Remove one of the % before the second z for this to work
Anonymous says:
Use double percents when executing the script from a batch file and single when executing from a command line.
Commandline:
C:\for /f %z in (hosts.txt) do pinghost.bat %z
From within a file:
for /f %%z in (hosts.txt) do pinghosts.bat %%z