Jump to content

Get MAC Address in DOS


cslee
 Share

Recommended Posts

I have a problem running "for" command in windows 98 command prompt.I have no problem to run this command in windows XP command prompt.but when I try to execute the "for" command through win98 startup disk to boot the system it return syntax error.The following are the "for" command in my batch file:

for /f "tokens=1,2* delims=- " %%1 in ('nbmac') do @echo %%1 %%2

nbmac is a application which i use to retrieve my network card mac address. your guiden is appreciate.thank you.

Link to comment
Share on other sites


Why not just use winipcfg in Windows 98? :D It should work fine... :)

http://www.practicallynetworked.com/support/winipcfg.htm

And if you want to log what it returns:

Replace <command> with one of winipcfg's commands! :rolleyes:

winipcfg <command> >> c:\log.txt

That should log everything that winipcfg returns in c:\log.txt! :D

Edit: My bad, I forgot winipcfg was a GUI interface. I believe ipconfig /all SHOULD still do the trick in Windows 98... I think I remember it being done on TechTV...

Link to comment
Share on other sites

I think you have misunderstand what i'm saying.What I like to do is I would like to take the mac address in pure dos and convert it to computer name so it won't have conflict computer name.This thing is apply in my network bootdisk. :rolleyes: or do you have any other way to generate random computer name in dos ? :)

Link to comment
Share on other sites

or

Maybe I should say I have make a network bootdisk.I like to use the mac address as computer name so that there is not conflict in computer name when there is many computer running together by using the network bootdisk.The "for" which I have place in the previous message was running very well in Windows XP command prompt.But when I try to run it in Win98 bootdisk/MSdos 6.22 ,it show the syntax error. :) I have totally no ideal on how to correct since I'm very new to batch script ptogramming.I hoping someone could help me to correct it. :rolleyes: Thanks.

Link to comment
Share on other sites

I use COMPNAME (search for it on Simtel.net). Because there is a very small chance that the random name generated with this program will be a duplicate of another I simply run net start a few times, running COMPNAME in between each attempt.

REM ==============================================================REM  Attempt to connect to the network 5 times.  Generate a newREM  random name each time in case we conflict with someone else.REM  Wait longer and longer each time we try.REM ==============================================================
REM 111111111111111111111111111111ewc #V#=0B   - First attempt ...#=07COMPNAME.EXE > NULGSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NULNET START > NULif errorlevel 1 goto logon
REM 222222222222222222222222222222ewc #=0B   - Second attempt ...#=07#+1+COMPNAME.EXE > NULGSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NULNET START > NULif errorlevel 1 goto logon
REM 333333333333333333333333333333ewc #=0B   - Third attempt ...#=07#+3+COMPNAME.EXE > NULGSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NULNET START > NULif errorlevel 1 goto logon
REM 444444444444444444444444444444ewc #=0B   - Fourth attempt ...#=07#+5+COMPNAME.EXE > NULGSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NULNET START > NULif errorlevel 1 goto logon
REM 555555555555555555555555555555ewc #=0B   - Fifth attempt ...#=07#+7+COMPNAME.EXE > NULGSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NULNET START > NULif errorlevel 1 goto logon
goto netError

Notes:

"ewc" is used for visual formatting and for inserting an increasing delay in seconds between attempts. Can be found on Simtel.net.

"gsar" is used to search and replace text in text files, in this case my system.ini file. Can be found on SourceForge.

The DOS version of net start actually initializes networking, unlike the Windows version which lists running services.

The example above jumps to the "logon" label if an attempt is successful, otherwise it retries a number of times before finally failing and jumping to the "netError" label.

This method hasn't failed yet on the (literally) thousands of times it's been used by myself or my co-workers.

Link to comment
Share on other sites

Even this is working but I do think this is not a very good ideal and working for me,since my program will initiliaze the computer name before connect to network. :rolleyes: So I hope it would be better to use mac address as computer in dos since mac address for each network card is very unique.So does any one know well in batch script for "FOR" command for windows 98/MSDOS 6.22. :)

Link to comment
Share on other sites

Even this is working but I do think this is not a very good ideal and working for me,since my program will initiliaze the computer name before connect to network.  So I hope it would be better to use mac address as computer in dos since mac address for each network card is very unique.So does any one know well in batch script for "FOR" command for windows 98/MSDOS 6.22.

Of course what you do is up to you, but I must point out that the script snippet I posted does initialize the computer name before connecting to the network. In fact it does exactly what you're asking for. Especially considering the "for" command in DOS does not have nearly as much functionality as the Win2K/XP version does and as such your method as posted will most likely not work under DOS.

Link to comment
Share on other sites

the /F parameter is the problem in the for-loop,

you need Command Extensions for that (2000+) see for helpquote below

so if you can manage to live without the options section (do the lineprocessing in the called command) you still can use FOR (looks like you just append the 2 variables to 1 again anyway)

for %%i in ('nbmac') do @echo %%i

gr /\/\o\/\/

-------------------------------

If Command Extensions are enabled, the following additional

forms of the FOR command are supported:

FOR /D %variable IN (set) DO command [command-parameters]

If set contains wildcards, then specifies to match against directory

names instead of file names.

FOR /R [[drive:]path] %variable IN (set) DO command [command-parameters]

Walks the directory tree rooted at [drive:]path, executing the FOR

statement in each directory of the tree. If no directory

specification is specified after /R then the current directory is

assumed. If set is just a single period (.) character then it

will just enumerate the directory tree.

FOR /L %variable IN (start,step,end) DO command [command-parameters]

The set is a sequence of numbers from start to end, by step amount.

So (1,1,5) would generate the sequence 1 2 3 4 5 and (5,-1,1) would

generate the sequence (5 4 3 2 1)

FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]

Link to comment
Share on other sites

  • 4 weeks later...
I use COMPNAME (search for it on Simtel.net).  Because there is a very small chance that the random name generated with this program will be a duplicate of another I simply run net start a few times, running COMPNAME in between each attempt.
REM ==============================================================

REM  Attempt to connect to the network 5 times.  Generate a new

REM  random name each time in case we conflict with someone else.

REM  Wait longer and longer each time we try.

REM ==============================================================

REM 111111111111111111111111111111

ewc #V#=0B   - First attempt ...#=07

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 222222222222222222222222222222

ewc #=0B   - Second attempt ...#=07#+1+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 333333333333333333333333333333

ewc #=0B   - Third attempt ...#=07#+3+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 444444444444444444444444444444

ewc #=0B   - Fourth attempt ...#=07#+5+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 555555555555555555555555555555

ewc #=0B   - Fifth attempt ...#=07#+7+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" %RAMDRIVE%\LANMAN\SYSTEM.TMP %RAMDRIVE%\LANMAN\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

goto netError

Notes:

"ewc" is used for visual formatting and for inserting an increasing delay in seconds between attempts. Can be found on Simtel.net.

"gsar" is used to search and replace text in text files, in this case my system.ini file. Can be found on SourceForge.

The DOS version of net start actually initializes networking, unlike the Windows version which lists running services.

The example above jumps to the "logon" label if an attempt is successful, otherwise it retries a number of times before finally failing and jumping to the "netError" label.

This method hasn't failed yet on the (literally) thousands of times it's been used by myself or my co-workers.

Hi there, i really like this script if only i could get it to work.

When i run the script i get an error can not bind twice in static mode

I will post a copy of my autoexec.bat & system.ini can you tell me if they are right

AUTOEXEC.BAT

@ECHO OFF

SET TZ=GHO+00:00

SET PATH=a:\net;a:\;

cd \net

CALL \NET\DOIT.BAT

REM ==============================================================

REM Attempt to connect to the network 5 times. Generate a new

REM random name each time in case we conflict with someone else.

REM Wait longer and longer each time we try.

REM ==============================================================

REM 111111111111111111111111111111

a:\net\ewc #V#=0B - First attempt ...#=07

a:\net\COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 222222222222222222222222222222

ewc #=0B - Second attempt ...#=07#+1+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 333333333333333333333333333333

ewc #=0B - Third attempt ...#=07#+3+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 444444444444444444444444444444

ewc #=0B - Fourth attempt ...#=07#+5+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 555555555555555555555555555555

ewc #=0B - Fifth attempt ...#=07#+7+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

goto netError

:logon

a:\net\netbind.com

a:\net\umb.com

a:\net\tcptsr.exe

a:\net\tinyrfc.exe

a:\net\nmtsr.exe

a:\net\emsbfr.exe

a:\net\net start

A:\NET\NET.EXE USE G: \\ghost\ghost

A:\NET\NET.EXE USE

SYSTEM.INI

[network]

filesharing=no

printsharing=no

autologon=yes

computername=homer

lanroot=a:\net

username=ghost

workgroup=london

reconnect=no

dospophotkey=N

lmlogon=0

logondomain=london

prefferedredir=full

autostart=full

maxconnections=8

[network drivers]

netcard=

transport=tcpdrv.dos,nemm.dos

devdir=a:\net

LoadRMDrivers=yes

[Password Lists]

*Shares=A:\NET\Shares.PW

I really need to get this DOS boot disk to change the computer name each time and your script id the closeest i have seen to doing it.

Can you help me out at all?

Link to comment
Share on other sites

Oh and the batch file only seems to try once i only see First attempt then it moves on.

could you email me a copy of your batch file & system.ini file so i can see how you have put it together. i will be forever in your debt

Mnay thanks

Link to comment
Share on other sites

Oh and the batch file only seems to try once i only see First attempt then it moves on.

could you email me a copy of your batch file & system.ini file so i can see how you have put it together. i will be forever in your debt

Mnay thanks

You've got some things backwards. The section in your "autoexec.bat" that starts at ":login" should happen before you try to connect to the network. Also get rid of that extra "net start" and try running "net init" before hand.

Eg. AUTOEXEC.BAT

@ECHO OFF

SET TZ=GHO+00:00

SET PATH=a:\net;a:\;

cd \net

CALL \NET\DOIT.BAT

a:\net\net init

a:\net\netbind.com

a:\net\umb.com

a:\net\tcptsr.exe

a:\net\tinyrfc.exe

a:\net\nmtsr.exe

a:\net\emsbfr.exe

REM ==============================================================

REM Attempt to connect to the network 5 times. Generate a new

REM random name each time in case we conflict with someone else.

REM Wait longer and longer each time we try.

REM ==============================================================

REM 111111111111111111111111111111

a:\net\ewc #V#=0B - First attempt ...#=07

a:\net\COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 222222222222222222222222222222

ewc #=0B - Second attempt ...#=07#+1+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 333333333333333333333333333333

ewc #=0B - Third attempt ...#=07#+3+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 444444444444444444444444444444

ewc #=0B - Fourth attempt ...#=07#+5+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

REM 555555555555555555555555555555

ewc #=0B - Fifth attempt ...#=07#+7+

COMPNAME.EXE > NUL

GSAR.EXE -f "-s**COMPUTERNAME**" "-r%COMPNAME%" A:\NET\SYSTEM.TMP A:\NET\SYSTEM.INI > NUL

NET START > NUL

if errorlevel 1 goto logon

goto netError

:logon

A:\NET\NET.EXE USE G: \\ghost\ghost

A:\NET\NET.EXE USE

goto End

:netError

echo There was an error.

:End

Also if you're going to use my script exactly at worded then you need to rename your "system.ini" to "system.tmp" and replace the computer name in the file with "**COMPUTERNAME**" (which is replaced by gsar in the script).

Eg. SYSTEM.TMP

[network]

filesharing=no

printsharing=no

autologon=yes

computername=**COMPUTERNAME**

lanroot=a:\net

username=ghost

workgroup=london

reconnect=no

dospophotkey=N

lmlogon=0

logondomain=london

prefferedredir=full

autostart=full

maxconnections=8

[network drivers]

netcard=

transport=tcpdrv.dos,nemm.dos

devdir=a:\net

LoadRMDrivers=yes

[Password Lists]

*Shares=A:\NET\Shares.PW

Give it another try and let us know how it goes. I'll help you if I can. I'd rather not post my own batch files and ini files as that would add another layer of complexity to what you're doing (my network Ghost disk is very elaborate).

Link to comment
Share on other sites

Thank you so much for your reply. I have changed the files as you said.

It loads everything up ok the it starts to go through the 1,2,3,4,5 attempt then just displays there was an error and the batch file stops

Do you know what might be up?

Thank you so so so so so so much for your help on this i cant thank you enough :)

Link to comment
Share on other sites

i took off the > NUL just so i could see what it is up to and when it runs it says

Unique Computer Name Generated

This Program Cannot be run in dos mode

There was an error

I downloaded all the files you said on your post. do you think i have the wrong gsar.exe? the gsar.exe i have is 32.6kb

Something is defo wrong. but i am so happy as i am 99% closer to achiving what i have been doing for the last few months. i can see a light at the end of the tunnel. :rolleyes:

Thanks again for all your help so far :)

Link to comment
Share on other sites

Ignore that last post. I downloaded gsar111.zip but that had the wrong gsar.exe so i then downloaded gsar110.zip and this seems to be better.

The issue i have now is that when i boot up with the disk everything is ok it gets the first attempt and then just sits there doing nothing

Do you know what might be up?

Cheers

Craig

Link to comment
Share on other sites

Right i am off home for the day mate. Could you please post as much info as you think would help me sort this issue out. I will prob be in bed when you are most of the way through your day what with the time diff

But thank you so much for your help on this problem

Talk to you soon mate

Craig

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.


×
×
  • Create New...