Computing.Net > Forums > Programming > ip addresses

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

ip addresses

Reply to Message Icon

Name: peacock
Date: October 2, 2007 at 15:48:14 Pacific
OS: various
CPU/Ram: various
Product: various
Comment:

I have been given this little project to do...
There are 1000 computers (thereabouts). Not all on the same network (necesarily).
One of the real problems of subdividing this forum is for little problems like this. Because whilst the problem isn't for MSDOS, well its not for any one windows platform, but for all of them.
I've been told there are nothing earlier than windows 98 and there are no linux or macs machines. The operating systems are either
Windows 98, NT 4.0, 2000 or XP
There are no vista machines yet.
The mission is this...
Every computer box has a station id written on the outside of the box.
What i have to do is to visit every computer and record the station id and its IP address. Its that simple. The IP addresses are assigned manually, they do not use DHCP.
So initially i thought i would have to type ipconfig <Enter> 1000 or so times, but then i had an idea, why not write a batch file and stick it on a floppy disk. So i wrote something like this
;This is for windows 98
echo off
cls
ipconfig /all /batch a:\ip.txt
ipconfig
pause
exit

The reason why there is the second ipconfig is i probably will have to do the manual record. imagine if the floppy disk corrupts on the last one!

Well of course it worked.... for the first one!
When i went to a second machine, it simply deleted the file and wrote a new one and of course it didn't enter the station id.
This process didn't work at all on the windows 2000 machines, there is no /batch option on the command line.
i tried
ipconfig /all ->a:\ip.txt
but this was rubbish!
i haven't tried windows XP or NT4.0 yet.
What i would like ideally for the file to do is...
i put the floppy in the drive and i click start /run and then i type in a:\ip <Enter>
What the batch file ask me for is the station id
Enter station id.:
and i type it in, say its abcd1234
after typing it in, the ip address info is displayed for me to write down, but it also adds all the IP address one at a time to the same file and then the program exits.
So after visiting 3 computers ip.txt will show
station id ip adress
abcd1234 192.168.0.1
abcd1235 192.168.0.2
xzcf0785 192.168.9.171
for example
i can have different batch files for different operating systems and they can even append data to different files, so long as it all works.
I would be grateful for any help you can give me, to help me not go mad. I've got one day to try it all out, otherwise its pen and paper only and the long winded ipconfig /all 1000 times.
Thank-you



Sponsored Link
Ads by Google

Response Number 1
Name: tonysathre
Date: October 2, 2007 at 16:10:24 Pacific
Reply:

@echo off
echo Computer ID: %computername% > %cd%\ip.txt
for /f "tokens=15" %%i in ('ipconfig /all ^| find "IP Address"') do echo %%i >> %cd%\ip.txt

"Computer security." — Oxymoron


0

Response Number 2
Name: Razor2.3
Date: October 2, 2007 at 17:47:53 Pacific
Reply:

That won't work for the Win9X machines.

VBScript coupled with WMI may be a viable option here, but Win98/ME comes with version 1.0, and the MS documentation doesn't do a very good job listing what I can and can't use for that version.

That said, you're probably safe with something like this:
ipconfig /all >> out.txt
echo ************************** >> out.txt


0

Response Number 3
Name: peacock
Date: October 2, 2007 at 17:49:26 Pacific
Reply:

Thank-you Tony for the effort i do appreciate it, and i have kept the code for future use. Unfortunately i may have not made the problem clear enough.

Its not the %computername% i need. There is some random station id. written on the outside of the computer box and i need to write that down as well.
Station id. ip address
abcd1234 192.168.0.1

i also noted that when i took the disk to the next computer and reran the script, it simply over wrote what was already there. So all that it does is write the ip address for one computer, but i have got over a 1000 to do.

i also had a go at rewriting my batch file as follows

1. echo off
2. cls
3. ipconfig /all >a:\ip.txt
4. copy a:\ip.txt a:\ip2.txt
5. edit a:\ip2.txt
6. ipconfig
7. pause
8. exit
Line 4 is supposed to copy the contents of ip.txt to ip2.txt. The result is that ip2.txt gets overwritten with ip.txt, so it doesn't append to the file.
Line 5 is so i could add the station id manually
Lines 6 - 8 - i still have to write a manual reocrd, just in case.
Can you help further with this?
Many thanks


0

Response Number 4
Name: peacock
Date: October 2, 2007 at 17:51:36 Pacific
Reply:

what does the >> do?
cos i wrote ipconfig /all >a:\x.txt
So i know that > means to ouput to a file.
Does >> append to a file?
I'm learning a lot thank-you


0

Response Number 5
Name: Razor2.3
Date: October 2, 2007 at 17:57:33 Pacific
Reply:

> = overwrite file
>> = append to file



0

Related Posts

See More



Response Number 6
Name: Fozzie
Date: October 2, 2007 at 20:49:38 Pacific
Reply:

It seems to me that running a batch file from a floppy would take longer than it would to just do it manually. Maybe a USB stick drive would be faster than manual.

Also, if 1000 unique IP addresses were assigned to 1000 PC's surely there has to be a record of station ID's and IP's already. Have you talked to the network admins? You may have to resort to bribery.

If there is no list then the reason is probably that there is a easy to understand system of assigning IP's (which the admins will tell you about hopefully) perhaps based on the station ID's.

And maybe I'm wrong and the place where you work has a seriously improvisational way of setting up networks. And it doesn't make sense that a supervisor would assign you the task if there was an easier way to get the info but even supervisors do some brainless things.


0

Response Number 7
Name: tonysathre
Date: October 2, 2007 at 22:22:23 Pacific
Reply:

What about this:

@echo off
ver | find "XP" > nul
if errorlevel 0 (
goto :_NT
) else (
goto :_Win9x
)

:_NT
for /f "tokens=15" %%i in ('ipconfig /all ^| find "IP Address"') do echo %%i >> %cd%\ip.txt
goto :eof

:_Win9x
ipconfig /all >> a:\ip.txt

I don't have a Windows 9x box to test this on so I don't know if it works, but it should.


"Computer security." — Oxymoron


0

Response Number 8
Name: FishMonger
Date: October 2, 2007 at 23:20:17 Pacific
Reply:

I'm going to assume that the people that setup the network weren't total newbees and the hostname of each station is the same as the station id that is written on the outside of the box. However, that might be a bad assumption.

My recommendation is to use nmap http://insecure.org/nmap/ (or similar program) to do a scan of the network. Here's an example of using nmap that will scan a network and return the IP address, hostname (as long as it can be resolved via dns or wins), and mac address (if run on the same segment).

C:\>nmap -sP 192.168.0.0/24

Here's another example that saves the scan is 3 different file formats (normal, xml, and gnmap [grepable]).

C:\>nmap -sP -oA network_scan 192.168.0.0/24


0

Response Number 9
Name: Mechanix2Go
Date: October 3, 2007 at 05:11:05 Pacific
Reply:

"seriously improvisational"

LOL

w9x, NT4 and NT5 are different in many ways.

I don't know the 9x/nt4 syntax but in NT5 you don't need the /all.

something like this:

============================
@echo off

if %1'==' echo call this bat with PCID && pause && goto :eof

echo ======================== >> a:\ip.txt
echo %1 >> a:\ip.txt
ipconfig | find "IP Address" >> a:\ip.txt

:eof



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 10
Name: peacock
Date: October 3, 2007 at 09:11:35 Pacific
Reply:

can anyone explain what the @ sybol means in front of echo off?


0

Response Number 11
Name: StuartS
Date: October 3, 2007 at 11:05:32 Pacific
Reply:

The @ symbol suppresses echo off from being displayed. Without it you would see echo off before the echo off command had executed.

Remove it and see what happens.

Stuart


0

Response Number 12
Name: peacock
Date: October 7, 2007 at 05:02:04 Pacific
Reply:

The memory stick idea mentioned above was no good because various people have extra addons such as cameras and other removable devices. I couldn't possibly know what drive letter my memory stick will be give, but if i use a floppy then i know its always 'A'.
Some of the older computers such as NT 4.0 do not recognise usb flash drives either.

I was going to use the program i wrote above, but extra information was required which i coudn't have known, which made the whole thing useless. So in the end i had to use the paper and pen method.

Thanks to everyone for all your help. I have noted many of them to try later.


0

Response Number 13
Name: tonysathre
Date: October 7, 2007 at 14:18:34 Pacific
Reply:

%cd% will work though because it expands to whatever the current working directory is.

"Computer security." — Oxymoron


0

Response Number 14
Name: Razor2.3
Date: October 7, 2007 at 17:19:06 Pacific
Reply:

peacock: I couldn't possibly know what drive letter my memory stick will be give
No, but you don't need to know. Simply double-clicking on the script in Windows will run the script from that directory. In other words, we don't need to know what the drive is.

tonysathre: %cd% will work...
Only on the WinNT line.

Basically, you should disable command extensions. If your script works, it'll probably work for Win9X. Should save you a bit of embarrassment.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: ip addresses

VBScript IP Address within range www.computing.net/answers/programming/vbscript-ip-address-within-range/14735.html

IP Address www.computing.net/answers/programming/ip-address/2728.html

IP address message www.computing.net/answers/programming/ip-address-message/4892.html