Need really simple code

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lkarelee
Posts: 2
Joined: 23 Jun 2008 06:52
Location: Austin, Texas

Need really simple code

#1 Post by lkarelee » 23 Jun 2008 07:03

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

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

#2 Post by jeb » 24 Jun 2008 16:13

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

Post Reply