[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1785
  • Last Modified:

Batch script that returns an ip address and a ping reply.

Does anyone know how to create a batch job to query a specific number of hosts (servers/workstations) and in return it will give me back their ip address and see if it receives a reply back from a ping?
0
mystikal1000
Asked:
mystikal1000
  • 3
  • 2
1 Solution
 
kfullartonCommented:
This might be what your looking for:

http://groups.msn.com/windowsscript/general.msnw?action=get_message&mview=1&ID_Message=11672

I could do it with a few more steps and file edits.  Create a list of IPs in excel, save as CSV file.  open it with notepad and replace commas with dots.  save it as "ips.txt".  From DOS, type "for /F %i in (c:\ips.txt) do ping -n 1 %i | find "Reply""

You could also do a "net view" which will return all workstations/servers in the domain.  A few edits and you could have a list that you could use just like the ips.txt file above.
0
 
mystikal1000Author Commented:
I also want to know if the host is pingable or not.

Down below is what I have, but it only retrieves the ip address and host name, not ping reply or request time out...
Does anyone know?

@echo off
setlocal
del /q ServerIP.csv


for /F "delims=" %%x in (servers.txt) DO CALL :PING %%x
goto :EOF

:PING
 echo Server : %1%
 ping -n 1 -w 10 %1 | for /f "usebackq tokens=2 delims=[]" %%y in (`find /i "%1"`) DO @echo %1;%%y >> ServerIP.txt
goto :EOF
0
 
kfullartonCommented:
If you're just trying to see what replies, The line I posted above will do that.  Here's the output:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\>ping -n 1 www.cisco.com | find "Reply"
Reply from 198.133.219.25: bytes=32 time=107ms TTL=114

C:\>ping -n 1 www.microsoft.com | find "Reply"

C:\>
0
 
mystikal1000Author Commented:
No, I also want the request time outs too.

I want a txt file that has all the hosts I want to ping.  I also want a batch file that will take the txt file and capture replies, request timeouts and hostname.
0
 
kfullartonCommented:
OK.  If you remove the find statement, do this:

"for /F %i in (c:\ips.txt) do ping -n 1 -a %i >> c:\results.txt"

All results will be redirected to c:\results.txt.  The ping will attempt to resolve the hostname through DNS.  If there is not a PTR record for the IP, no name will be returned.  Maybe you can provide an example of what your text file would ideally look like.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now