Page 1 of 1

Need really simple code

Posted: 23 Jun 2008 07:03
by lkarelee
I have batch file creation experience - but in another language - I need to create a DOS batch file very quickly - so I could use some help.

1. I want the batch to read a list of IP Addresses (they can either be on
a separate list or in the batch file) and create a variable called %add%
2. I want to then do a simple ping command (this part I already have working) for each IP address
3. If a there is an error - generate a mail message.
4. Translate that IP address into a server name and use that server name as part of the mail message.

The parts I'm having trouble with is 1) reading a list of values and 4) Translating each IP into the appropriate server name.

Can anyone help? Thanks

Posted: 24 Jun 2008 16:13
by jeb
Hi,

build a file named IPList.txt like
192.168.0.1
10.0.47.11
10.0.08.15
...

Read the file and get the hostname

Code: Select all

@echo off
setlocal enabledelayedextensions

for /F "tokens=*" %%i IN (IPlist.txt) DO (
  echo IP is %%i
  rem do something with this ip, like
  ping %%i

  rem echo the name
  ping -a -n 1 -w 1 %%i

  rem Take this function from the dostips library
  call :getHostName %%i hostName
  echo !hostName!
)


jeb