We help IT Professionals succeed at work.

How to include non-responsive ping results in batch script

essdeekay
essdeekay asked
on
725 Views
Last Modified: 2010-04-21
I have a current script to convert hostnames to IP addresses which works great apart from the fact if a machine doesn't respond with an IP address, it gets ignored completely.  What can I add in to ensure that all hostnames in the script get a corresponding response in the resulting CSV file, whether the hostname responds to a ping request or not?

Many thanks.
for /f %%i in (hosts.txt) do for /f "tokens=2 delims=[]" %%j in ('ping -n 1 %%i ^| find /i "%%i"') do @Echo %%i,%%j >> host2ip-results.csv

Open in new window

Comment
Watch Question

Systems Engineer
CERTIFIED EXPERT
Top Expert 2007
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I actually wanted to get the 'System may be offline' message in to the CSV file, but as your answer was so good it was easy to make the necessary changes myself.  Many thanks!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.