Windows

Create an IP address tracking batch tool in Windows XP Pro

Finding your network's free IP addresses in Windows XP Pro can work a little too well, giving you more entries than you can easily manage. Here's how to narrow your search for unused IP addresses and output the results to a short, easy-to-read text file.

When you're troubleshooting DHCP problems in Windows XP Pro and want to find out which addresses in a range of IP addresses aren't in use, you may open a command prompt window and launch a ping loop with the For…In…Do command. For example, to find out which IP addresses aren't being used in the range 192.168.1.1 to 192.168.1.100, you might use the command For /L %f in (1,1,100) Do Ping.exe -n 2 192.168.1.%f.

This command will report all the IP addresses, whether in use or not; you'll also have to scroll through a vast number of entries on the command line. You can avoid these inconveniences with a short batch file that returns only those IP addresses that aren't in use, and then compiles the results in a text file. Here's how:

  1. Launch Notepad and type the following commands:
    @Echo off
    date /t > IPList.txt
    time /t >> IPList.txt
    echo =========== >> IPList.txt
    For /L %%f in (1,1,100) Do Ping.exe -n 2 192.168.1.%%f | Find
    "Request timed out." && echo 192.168.1.%%f Timed Out >>
    IPList.txt && echo off
    cls
    Echo Finished!
    @Echo on
    Notepad.exe IPList.txt
  2. Save the file as IPTracker.bat and close Notepad.

Keep in mind that the entire For…In…Do command consists of several commands strung together with &&s. The command begins with the word For and ends with the word off, and the entire command must be on one line. Also, be sure to replace the example numbers with numbers from the IP addresses you wish to track.

Now when you troubleshoot a DHCP problem, you can locate and double-click the IPTracker.bat file in Windows Explorer, and then launch an IP address tracking tool batch that will find only those addresses that aren't in use and then display the results in Notepad. (In this case, the saved batch file becomes an IP address tracking tool that can be created once and used over and over.)

Note: This tip applies only to Windows XP Professional.

Miss a tip?

Check out the Windows XP archive, and catch up on our most recent Windows XP tips.

Stay on top of the latest XP tips and tricks with our free Windows XP newsletter, delivered each Thursday. Automatically sign up today!

About

Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.

60 comments
SysAdminII
SysAdminII

Doesn't Angry IP Scanner do basically the same thing? It shows what IP's are dead and which ones are alive. I have seen instantances where it shows a IP that is dead but actually still alive since the connection blocks ICMP packets.

MarkJL0@OptOnline.net
MarkJL0@OptOnline.net

Another version. @echo off setlocal enabledelayedexpansion set BASE=192.168.1 set START=1 set END=255 cls if "%1" neq "/?" goto :Tell if "%1" neq "?" goto :Tell goto :Cont :Tell echo. echo Ping a range of IP addresses to see if they are found. echo Put results in the file: IPList.txt. echo. echo Syntax: %0 [ base IP range address (Default: 192.168.1) echo [ beginning octet (Default: 1) echo [ ending octet (Default: 255) ] ] ] echo (Note: Arguments within brackets are optional.) echo. echo Example of argument useage: %0 192.168.1 100 150 echo which will check IP addresses 192.168.1.100 through 192.168.1.150. echo. echo M.Lindemann 7/14/07 goto:EOF ) :Cont if '%1' neq '' set BASE=%1 if '%2' neq '' set START=%2 if '%3' neq '' set END=%3 date /t > IPList.txt time /t >> IPList.txt echo ======================= >> IPList.txt for /L %%f in (%START%,1,%END%) do ( echo Checking %BASE%.%%f ... ping.exe -n 1 -w 100 %BASE%.%%f | find.exe "Request timed out." > nul if !ERRORLEVEL! equ 0 echo %BASE%.%%f - Timed Out >> IPList.txt if !ERRORLEVEL! neq 0 echo %BASE%.%%f - Found >> IPList.txt echo off ) echo. echo Finished! echo. if 0 equ 1 ( notepad.exe IPList.txt ) else ( echo ----- IPList.txt ---------------------------- more.com IPList.txt echo ------end of IPList.txt --------------------- )

davejohnson
davejohnson

How can I use these scripts with a list of non-sequential IP addys that I have listed in a text file?

thomasdohling
thomasdohling

The batch file IPTracker.bat was created as directed. While running it, the message "FIND: Parameter format not correct" was displayed. Solution? Correct FIND format?

nhuffnagle
nhuffnagle

as long as the 'single line' format is observed, works great on Win2K.

jdelatorre
jdelatorre

$iparray = 1..249 foreach ($ip in $iparray) { [string]$ping = ping.exe -n 2 192.168.249.$ip if ($ping.contains("bytes=")) { write-host "192.168.249.$ip is online" } else { write-host "192.168.249.$ip is OPEN!!" } }

Questor1
Questor1

Is there a IP address tracking batch tool available for Win2K? Why is this batch tool restricted only to winXP?

YetAnotherTechie
YetAnotherTechie

In our organisation, there could easily be hundreds of PCs switched off the have valid leases in the DHCP tables/AD. Wouldn't a script that audits DHCP produce information that's a bit more reliable?

Greg Shultz
Greg Shultz

FIND: Parameter format not correct then you've made a mistake! When you copy and paste this batch file into a Notepad document, you NEED to make sure that the For command is ALL on one line as explained in the article. In other words, the following command MUST be on one line: For /L %%f in (1,1,100) Do Ping.exe -n 2 192.168.1.%%f | Find "Request timed out." && echo 192.168.1.%%f Timed Out >> IPList.txt && echo off To make sure that it is: 1) After you paste the batch file into Notepad, pull down the Format menu and disable the Word Wrap feature. 2) Position the cusor at the beginning of the line that begins with the word For. 3) Press the End key, press the Space bar, and then press the Delete key. 4) Repeat step 3 until the command is on one line that begins with the word For and ends with the word off 5) Save the file It should now run perfectly!

mitch_marcotte
mitch_marcotte

Did't work for me. I get a Find error "FIND: Parameter format not correct". Too bad, it looks cool. I tried puting in the IP but I still get the error. Anyone got a working example ?

MarkJL0@OptOnline.net
MarkJL0@OptOnline.net

@echo off setlocal enabledelayedexpansion set FILE=IPListIn.txt cls if "%1" equ "/?" goto :Tell if "%1" equ "?" goto :Tell goto :Cont :Tell echo. echo Ping a set of IP addresses defined in a file to see if they are found. echo Put results in the file: IPList.txt. echo. echo Syntax: %0 [ filename of text file containing IP addresses ] echo. echo (Note: Argument within brackets is optional. Default: IPListIn.txt) echo. echo M.Lindemann 7/14/07 goto:EOF :Cont if '%1' neq '' set FILE=%1 date /t > IPList.txt time /t >> IPList.txt echo ======================= >> IPList.txt for /F %%i in (%FILE%) do ( echo Checking %%i ... ping.exe -n 1 -w 100 %%i | find.exe "Request timed out." > nul rem If only "found" IP addresses are desired, add "rem" in front of this next line. if !ERRORLEVEL! equ 0 echo %%i - Timed Out >> IPList.txt rem If only "not found" IP addresses are desired, add "rem" in front of this next line. if !ERRORLEVEL! neq 0 echo %%i - Found >> IPList.txt echo off ) echo. echo Finished! echo. if 1 equ 1 ( notepad.exe IPList.txt ) else ( echo ----- IPList.txt ---------------------------- more.com IPList.txt echo ------end of IPList.txt --------------------- )

tektom
tektom

The line containing FIND has to be all ON ONE LINE starting with "for" and ending with "off" as it was stated in a few earlier posts in the same thread.

bigmenace1ster
bigmenace1ster

the same script should work for w2k. I have not tested it myself yet...but I will in the near future..

belbinclive
belbinclive

I'm not sure why you'd want to audit DHCP with a script when there's a perfectly good GUI tool with which to look at it. If you want to play around with the data, you can export to a delimited text file and then import that into e.g. Excel or Access. If you're still running WINS, then that has its own GUI and usually has even more history in it - if not, then DNS also has a GUI (but I'm not sure what level of history it retains). Both WINS and DNS support delimited text export. I would see this script as being useful in identifying unused addresses that are outside your DHCP scopes e.g. when you want a spare static address for a new server/printer/whatever. I suppose you could use ping -a blah to identify addresses which resolve to a name but which don't respond, but changing the ping command switch almost cetainlky won't be enough to get that result from this script.

mikec
mikec

Thanks helpful tool.

uberg33k50
uberg33k50

Philip...that is a very cool tool. Much faster than the batch file too. OK, I'm done for the day...I will be playing with this.

1RealTruth
1RealTruth

I do not get an error when the file runs. It runs fine but.... I have never gotten any addresses in the IPList.txt file. The only thing that shows up is the Date and time. The rest it blank.

thomasdohling
thomasdohling

Thanks for the clarification. However, the pinging hung up on our .10 in spite of the fact that we have more 100 addresses. Any solution?

jan.ostlund
jan.ostlund

Hi Agree with Greg, can easly be error in the BAT file if you don't keep the complete FOR-command in the same line (happend to me). Another matter to check is the output of ping when it times out (language specific). I had to change the FIND string to match my local language. Also trimmed the BAT-file a bit: - Entering the BASE ip adress at the begining of the file instead of in 3 places. - Possiblity to enter starting and ending address at commandline if whole range is not to be scanned. - Displaying what IP is processed. @Echo off SET BASE_IP=192.168.30. SET START_IP=%1 SET END_IP=%2 IF "%START_IP%"=="" SET START_IP=1 IF "%END_IP%"=="" SET END_IP=254 date /t > IPList.txt Time /t >> IPList.txt echo =========== >> IPList.txt For /L %%f in (%START_IP%,1,%END_IP%) Do ECHO PINGing %BASE_IP%%%f && Ping.exe -n 2 %BASE_IP%%%f | Find "timeout" && echo %BASE_IP%%%f Timed Out >> IPList.txt && echo off cls REM --- CleanUp SET BASE_IP= SET START_IP= SET END_IP= Echo Finished! @Echo on Notepad.exe IPList.txt Regards Jan

essar.max
essar.max

@Echo off date /t > IPList.txt time /t >> IPList.txt echo =========== >> IPList.txt For /L %%f in (1,1,100) Do Ping.exe -n 2 192.168.100.%%f || Find "Request timed out." && echo 192.168.100.%%f Timed Out >> IPList.txt && echo off cls Echo Finished! @Echo on Notepad.exe IPList.txt

don
don

I did exactly what was told and it doesn't work

carl0ski
carl0ski

I wouldnt even bother using this since the 1. output isnt very useful 2. Windows XP blocks ping ICMP by defaults so wont respond any heres what i use under BASH ARPING can find devices that block ping for i in `seq 1 254`; do a=$(arping -c 1 192.168.23..$i|grep -i unicast); echo $i $a|cut -d " " -f,1,6;done and my output 1 [00:xx:xx:49:7C:EE] 2 [00:06:xx:4E:70:CA] 3 [00:14:xx:2A:16:99] 4 [00:14:xx:32:36:80] 5 [00:14:xx:F9:E7:C9] 6 [00:02:xx:7B:21:FA] 7 [00:04:xx:4C:1A:CE] 8 9 [00:09:xx:F1:09:01] regular output ARPING 192.168.23.8 from 192.168.23.88 eth0 Sent 1 probes (1 broadcast(s)) Received 0 response(s) note .8 is not in use

xpgpx
xpgpx

this would be nice to have. does anyone else get this error?

defo1
defo1

This is what happens when an article is written about something that hasn't even been tested. Makes the tech site look bad, probably because it is.

YetAnotherTechie
YetAnotherTechie

We also have Unix based DHCP, and with 14,000 PCs, a script would be absolutely necessary. You're right about the GUI for AD based DHCP, but it's still a bit of manual labour having to read through it to see unallocated IP addresses. Anyway, my point was that just pinging sequential IP addresses is an unreliable way of determining unallocated IP addresses (at least in a medium to large IT infrastructure).

holly.gibson
holly.gibson

Thanks for sharing...I just tried it and wow. We use Dameware and it is good too.

deqani
deqani

Jan, I have tried Jan's sript and it works fine. Thanks man Regards Erton

Lost Cause?
Lost Cause?

I tried the batch file from the first post. I kept getting a "Request Timed Out" message. This version (by Jan) works!

Professor-X
Professor-X

Thanks for your help, much appeciated.

ESchlangen
ESchlangen

The vertical bar is a pipe command to push output through the Find program, not OR logic.

Chris_Muncy
Chris_Muncy

This is more of an exercise on HOW this can be done with a simple script. Yes, there are several freeware/shareware/commercial utilities that can do this but being able to see this script and understand how it works and being able to manipulate it. I personally would never use this method because it is too slow. But there are those that would take this, play with it, do some pretty neat stuff while learning about batch commands, and be totally satisfied that they got somethign accomplished and learned a thing or two in the process.

BamSec1
BamSec1

essar.max@ gave an example which allows [ENTER]s and it works PERFECTLY. Add to that KenDAWG's -w 1 before the -n 2, i.e. For /L %%f in (1,1,100) Do Ping.exe -w 1 -n 2 192.168.100.%%f || Find and the thing does its work 300% faster! I find it a good little "freeware" utility.

paul.eggers
paul.eggers

I downloaded the LanSpy, and yes, it is cool. But I don't see where it shows the free IP addresses.

marsatkhed1
marsatkhed1

Yes I am also getting the same error.Please help me

Bob Oso
Bob Oso

Too bad. TechRepublic, got an editor?

J.C.Alexandres
J.C.Alexandres

It works, but your text might beigng truncated, just be sure you don't have the Word Wrap parameter set in Notepad.

nazeemjansen
nazeemjansen

Make sure this is on 1 line "For /L %%f in (1,1,100) Do Ping.exe -n 2 192.168.0.%%f | Find "Request timed out." && echo 192.168.0.%%f Timed Out >> IPList.txt && echo off"

juan18_c
juan18_c

Man where do u guys come up with this stuff?. Great lil batch thanks for posting this good stuff. KEEP THEM COMIN' ps did I mention u da man!!!??

No name specified
No name specified

very scary to think that there are those who call themselves LAN Admins or Tech Support, but who cannot differentiate between the EDITOR of an article (who wrote the script for WinXP) and a colleague who posts a comment to such article (who happens to not have tested the script in Win2k). Likewise there are all those who do not seem capable of following simple instructions like "the entire command must be on one line". For he/she who wrote 'I kept getting a "Request Timed Out" message', that is exactly the point of this script, to show you the addresses that are NOT in use, thus any address that times out is not in use at the moment. (Please READ the first line of the paragraph after the "Takeaway".) For the non-DOS users, the | before the Find is a PIPE symbol, which, on your keyboards looks like a : (colon), but with two little lines instead of periods. If you type it at the DOS prompt you will see what it really looks like, unlike Notepad or any other Win-based app which show a solid line. Cheers.

lawrence.bordeaux
lawrence.bordeaux

Mike: Good choice of words. Hard to understand why people would make such comments, particularly when the file in the original post ... actually works ...

Mike
Mike

This is what happens when a comment is written about something that hasn't even been read. Makes the tech look bad, probably because he is.

T0nz
T0nz

What? Other NOS's? Where?

belbinclive
belbinclive

Like Jorge says, we tend to forget non-windows NOSs, especially with this starting out as a Windows XP discussion 'n all ;-) I don't know any unix stuff - perhaps the Windows DHCP GUI can query a unix DHCP database? (Do RFCs go so far as to define its actual structure?) If it can, then you could do the export to Excel/Access thing which might (or might not) help. Obviously I don't do enough of this stuff - I can't imagine a situation where you'd need to identify individual unused addresses which are managed by a DHCP server, but I can see how knowing *how many* are unused would be useful!

J.C.Alexandres
J.C.Alexandres

I am agree with you Iain, us Windows dudes sometimes forget there are many other NOS out there!

Mike
Mike

I'm sure that installing tons of freeware onto your PC and network keeps everything in tiptop shape. I'm sure that your manager knew that you were wasting your time searching the Internet for superfluous freeware that duplates tools already built into the operating system, he might want to have words..

elrico-fantastica
elrico-fantastica

*edit* this is supposed to reply to the OP i know its fun to script but any freeware ping sweeper can ping ur subnet and return all active and none active IP's in seconds. doing it this way is just making work for yourself and making yourself take much longer to perform a very simple task. im sure if your taking time to write scripts for an operation that would take other techs 2 mouseclicks ur manager may have words.

rpost
rpost

Yes, check for word wrap off, and then watch for typos. Spacing and the wrong character (i.e. an ampersand instead of a percent sign) can ruin an otherwise excellent command. It took a few tries, but it works!

tom.armes
tom.armes

Same error, after correction works great Thanks

ddevenesan
ddevenesan

Thanks, I had the same error. Now works after removing word wrap and bringing the For command line to a single line.

KenDAWG
KenDAWG

Change the ping command to the following: For /L %%f in (1,1,100) Do Ping.exe -w 2 -n 1 192.168.80.%%f | Find "Request timed out." && echo 192.168.80.%%f Timed Out >> IPList.txt && echo off that should work for you.

juan18_c
juan18_c

is there a way of speeding it up mine is hanging at top 40's ie: 192.168.10.4X etc.. thanx

Editor's Picks