Sunday, August 29, 2010

Getmac and collecting MAC addresses

As in, getmac, the command, not Get Mac, something you should do if you a) Need a computer, and b) Have too much money to spend on one.

Anyway, I recently found a new command line command in Windows, called
getmac, which rather unsurprisingly, returns the machine's MAC address for all available adaptors. The usage for getmac is as follows:

GETMAC [/S system [/U username [/P [password]]]] [/FO format] [/NH] [/V]

This tool enables an administrator to display the MAC address
for network adapters on a system.

Parameter List:
/S system Specifies the remote system to connect to.

/U [domain\]user Specifies the user context under
which the command should execute.

/P [password] Specifies the password for the given
user context. Prompts for input if omitted.

/FO format Specifies the format in which the output
is to be displayed.
Valid values: "TABLE", "LIST", "CSV".

/NH Specifies that the "Column Header" should
not be displayed in the output.
Valid only for TABLE and CSV formats.

/V Specifies that verbose output is displayed.

/? Displays this help message.

GETMAC /S system /NH /V
GETMAC /S system /U user
GETMAC /S system /U domain\user /P password /FO list /V
GETMAC /S system /U domain\user /P password /FO table /NH

Getmac is supposedly able to get the MAC from a remote computer as well as the local computer, although I haven't used that functionality. I've used it in a batchfile deployed and executed on a bunch of machines using Symantec Ghost to gather MAC addresses from new machines on our network. This is helpful because we need the MAC's for our wireless MAC filtering. For reference, the batchfile is as follows:

@echo off
net use X: \\\MACs /USER:DOMAIN\username password
REM Get Mac and Computer Name and store in CSV
getmac /v /fo csv | find "Wireless" >%TEMP%\mactemp.txt
set /p macoutput=<%TEMP%\mactemp.txt
del /Q %TEMP%\mactemp.txt
echo %macoutput%,%computername% >>X:\MAClist.csv
net use X: /DELETE

As you can see, getmac is capable of grabbing the MAC and other details in CSV format, this tiny batch takes that info and adds the computers NETBIOS name in as an identifier, resulting in a CSV file written to a network share that contains each machines MAC and computer name, one per line. You can substitute the find "Wireless" for find "Local" if you need the wired MAC of a machine. You can also remove the pause at the end, I just used that in testing so I could see any error output before the DOS windows disappeared.

Until next time!

No comments: