Rob van der Woude's Scripting Pages

Find your computer's MacAddress

In both Windows NT and OS/2 Warp, the MacAddress of your computer's network adapter can be found using the NET CONFIG command.
I will try to explain an NT "batch file" (one command line, actually) that will do just that on this page.
The complete "source" can be found at the end of this page.
The OS/2 Warp version will not be explained. I created it just for fun, to see if it were possible. However, since I needed a lot of "dirty tricks" to replace NT's FOR options, I think Rexx would have been more suited for this task.
The Windows 95/98 version uses NBTSTAT -a to get the MacAddress.

The latest addition is a DOS version by Robert L. Baer.
It is meant for MS Client 3.0, the MS network client for MS-DOS, used mainly in network boot diskettes for unattended installs.

 

In NT, typing NET CONFIG will display a result like this:

The following running services can be controlled:


   Server
   Workstation

The command completed successfully.

Typing NET CONFIG SERVER will display something like this:

Server Name                           \\MYSERVER
Server Comment                        

Software version                      Windows NT 4.0
Server is active on                   NetBT_W30NT1 (002000123ABC) NetBT_W30NT1 (002000123ABC) Nbf_W30NT1 (002000123ABC) 

Server hidden                         No
Maximum Logged On Users               Unlimited
Maximum open files per session        2048

Idle session time (min)               15
The command completed successfully.

Whereas typing NET CONFIG WORKSTATION will display something like this:

Computer name                        \\MYSERVER
User name                            Administrator

Workstation active on                NetBT_W30NT1 (002000123ABC) Nbf_W30NT1 (002000123ABC)
Software version                     Windows NT 4.0

Workstation domain                   MYDOMAIN
Logon domain                         MYDOMAIN

COM Open Timeout (sec)               3600
COM Send Count (byte)                16
COM Send Timeout (msec)              250
The command completed successfully.

As you can see, the parameters we used for NET CONFIG were the ones supplied by the NET CONFIG command itself.

We can use this to extract all NET CONFIG information at once for any PC running NT, either server or workstation:

@ECHO OFF
FOR /F %%A IN ('NET CONFIG ˆ| FIND /V ":" ˆ| FIND /V "."') DO (
	ECHO ______________
	ECHO.
	ECHO  %%A
	ECHO ______________
	ECHO.
	NET CONFIG %%A
)

Or, if you prefer the command line:

@FOR /F %A IN ('NET CONFIG ˆ| FIND /V ":" ˆ| FIND /V "."') DO @ECHO ______________ & ECHO. & ECHO  %A & ECHO ______________ & ECHO. & NET CONFIG %A
Notes: (1) By using FIND /V ":" ˆ| FIND /V "." the "header" and "footer" lines are removed, in a language independent way.
You may want to add FIND " " to remove the empty lines too.
  (2) In case your browser doesn't display this the right way: the character preceding the pipe symbol (|) is a caret (^). It is the escape character for the NT command line.

The output will look like this:

______________ 
 
 Server 
______________ 
 
Server Name                           \\MYSERVER
Server Comment                        

Software version                      Windows NT 4.0
Server is active on                   NetBT_W30NT1 (002000123ABC) NetBT_W30NT1 (002000123ABC) Nbf_W30NT1 (002000123ABC) 

Server hidden                         No
Maximum Logged On Users               Unlimited
Maximum open files per session        2048

Idle session time (min)               15
The command completed successfully.


______________ 
 
 Workstation 
______________ 
 
Computer name                        \\MYSERVER
User name                            Administrator

Workstation active on                NetBT_W30NT1 (002000123ABC) Nbf_W30NT1 (002000123ABC) 
Software version                     Windows NT 4.0

Workstation domain                   MYDOMAIN
Logon domain                         MYDOMAIN

COM Open Timeout (sec)               3600
COM Send Count (byte)                16
COM Send Timeout (msec)              250
The command completed successfully.

You may combine this example with one or more FIND based filters plus FOR /F to extract any network related information you want.
The network adapter's MacAddress, for example:

@ECHO OFF
FOR /F %%A IN ('NET CONFIG ˆ| FIND /V ":" ˆ| FIND /V "."') DO FOR /F "TOKENS=2,3 DELIMS=()" %%X IN ('NET CONFIG %%A ˆ| FIND " active "') DO SET MacAddress=%%X
ECHO MacAddress=%MacAddress%

 

Click to download source
Download the sources of all versions

 


page last modified: 2011-11-18; loaded in 0.0036 seconds