| Member with 1 posts. THREAD STARTER | | | |
Batching: Get a hostname and IP from a list of file names I'm working on a script right now and am stuck. What I've got is a script that reads a list of filenames in a directory and converts those filenames to hostnames (each file is named HOSTNAME.log) and dumps these to a log, then runs another command on that log to get the IP addresses for the host names and puts this in a second log, and then finally goes through that second log to strip out addresses in a certain subnet and give me the final output in a third log.
So far, this part all works - I get a clean list of IPs. What I would LIKE it to do is give me a final list of not just the IP addresses, but hostnames as well (preferably something formatted like 255.255.255.1 HOSTNAME.domain.net), and I'd like it to create only one single file, not two interim files and a final clean output.
I've been modifying my script to try and add the hostname part, but so far haven't had any luck. What am I missing? This is the error I keep getting:
L:\>if exist c:\ipaddresses.log del c:\ipaddresses.log
i` was unexpected at this time.
L:\> for /f "skip=3 delims=: tokens=2 usebackq" i`) do @echo j >> c:\ipaddres
ses.log
Code: REM @ECHO OFF
REM ^^ watching the code
REM ------------------------------------------------------
REM Read the file names in the log directory on the server,
REM convert those file names to a list of hostnames.
REM ------------------------------------------------------
cd %1
if exist c:\names.log del c:\names.log
for /F "delims=" %%j in ('dir c:\Directory /A-D /B /O:GEN') do echo %%~nj >> c:\names.log
REM ------------------------------------------------------
REM Read the list of hostnames, convert them to a list of
REM hostnames / IP addresses.
REM ------------------------------------------------------
if exist c:\ipaddresses.log del c:\ipaddresses.log
for /f %%i in (c:\names.log) do (
for /f "skip=3 delims=: tokens=2 usebackq" %j in (`nslookup %i`) do @echo %i %j >> c:\ipaddresses.log
)
REM ------------------------------------------------------
REM Clean up our IP address file to strip out IPs within
REM the local group
REM ------------------------------------------------------
if exist c:\conlog.log del c:\conlog.log
type c:\ipaddresses.log |findstr /V /E 192.168.*.* >> c:\conlog.log |