Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Ping computers from txt / csv

Posted on 2006-04-21
6
Medium Priority
?
1,594 Views
Last Modified: 2012-06-27
ok I have had a look at other questions on here about this and I'm struggling to get them to work correctly.
What I have is a txt /csv file listing host names of computers
What I want is to ping this list and log result to a txt /csv file.
I would like the result file to contain the host name and then the IP address and the time & date, if the host name doesn't respond I would like it to just so unable to connect or something like this.

I know this must be possible but I'm very new to this.  I don't mind if I have to enter the syntax directly into the into the cmd prompt or if its a batch file.

Can anyone help, this is quite urgent
0
Comment
Question by:coch
  • 3
  • 2
6 Comments
 
LVL 3

Expert Comment

by:simko
ID: 16505575
you can use nmap<or other scan sw> for this and than redirect the output to a txt file

for x smaple like this
nmap -sP 192.168.3.0/24 > /tmp/out

this will ping all the hosts in the 192.168.3.0 subnet ant the result will be stored in the /tmp/out directory

in M$ W it will work also but you canot redirect the output with >

regards
R.
0
 

Author Comment

by:coch
ID: 16505634
thanks but its not quite what I'm looking for.  What I have is query output from Active Directory of all NT4 machines that have changed their passwords since 10th April 2006.  What I want to do is to ping each hostname in this list and log the results.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16505654
A batch file like this should work .... mangled from an existing one that does net use drive mapping checks to a series of servers so may be some typos:

using a file hostlist.txt entered as

hostname,ipaddress
nexthost,nextipaddress

it creates logfile.txt. PING doesn't return an errorlevel on all Windows OS's so try it and see:

PING knownhost
echo %errorlevel%
PING duffaddress
echo %errorlevel%

if this returns something other than 0 it should work...

set logfile=logfile.txt
set hostlist=hostlist.txt
for /F  "tokens=1,2 delims==," %%i IN (%hostlist%) DO call :pinghost %%i %%j
goto end

:pinghost
  SET SERVER=%1
  SET IPAD=%2
  ping -n 1 %ipad%
  if "%errorlevel%"=="0" echo PING to %SERVER% (%IPAD%) OK >> %logfile%
  if not "%errorlevel%"=="0" echo PING to %SERVER% (%IPAD%) FAILED >>%logfile%
goto end

:end
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
LVL 43

Accepted Solution

by:
Steve Knight earned 2000 total points
ID: 16505667
If you haven't got IP addresses in the file then change the for line to

set logfile=logfile.txt
set hostlist=hostlist.txt
for /F  %%i IN (%hostlist%) DO call :pinghost %%i
goto end

:pinghost
  SET SERVER=%1
  ping -n 1 %server%
  if "%errorlevel%"=="0" echo PING to %SERVER% OK >> %logfile%
  if not "%errorlevel%"=="0" echo PING to %SERVER% FAILED >>%logfile%
goto end

0
 

Author Comment

by:coch
ID: 16506399
works  a treat dragon-it, thank you
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 16506405
Thought it should :-)  Thanks for the points.

Steve
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this article I will be showing you how to subnet the easiest way possible for IPv4 (Internet Protocol version 4). This article does not cover IPv6. Keep in mind that subnetting requires lots of practice and time.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

577 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