Posted by: paragon | December 24, 2007

How do I get a MAC address via command line?

Why do I want a MAC address?

When computers talk over TCP/IP or UDP/IP the computers whom wish to speak to the destination IP computer ARP for the destination computer’s MAC address. The TCP/IP implementations require the IP to MAC translation and in reverse (RARP). This is the only way data gets transferred over the internet, by going through the layers from layer 7 to layer 1 and back. Hence when you send a packet to an IP address, the Network layer finds the destination MAC and sends the packets to that MAC address. In a LAN setting, you usually hit the destination ethernet card yourself through maybe some switches or hubs. In an internet setting, you go through various routers which do some analysis of TCP/IP headers and it finally arrives at the destination ethernet card. You must realize that every ethernet card in the world has a unique MAC address.

When you are a Winsock programmer dealing exclusively with sockets, I doubt you would care what the MAC addresses of the related NICs (Network Interface Card) are because you would never need to know about them. This is a low level issue which one needs not be exposed to in a network programming environment.

There are specific reasons why you may need to know the MAC address. Personally I had to write the Media Access Control Layer in an HDL language at one point. I had hard coded the FPGA to a certain MAC and created a static ARP so that I could write sockets software on my PC which would send UDP packets to my MAC. The MAC would then decipher and verify the checksum, and CRC of the UDP and MAC packets. It would then take the payload and forward it along to an RS232 interface. The RSR232 interface was connected to a Bluetooth device via RFCOMM. Your reason for knowing a MAC address may be different.

We will deal with enumerating the MAC address of all the NICs in your computer in a Windows environment.

Deciphering the 48-bit MAC address

The 48-bit MAC address is a globally unique identifier. Each ethernet card in the world has a unique MAC address. The first 24 bits correspond to the Organizationally Unique Identifier. The second 24 bits is administered by the company or organization that the OUI has been assigned to. You will notice that all 3Com cards, for example, will have the same OUI, the first 3 octets in a MAC address.

How do I get a MAC address via command line?

Okay, there are several command line utilities to get your MAC address. The first one that comes to mind is GetMAC. Simply open a command prompt and type GetMAC and it will return your 48-bit MAC address in the following format:

Physical Address   Transport Name ================== ==================================================== 00-40-CA-B5-5B-06  \Device\Tcpip_{B249BB63-9574-4061-817A-D62E1D12072F}

The next method of doing it is writing IPCONFIG /ALL, this will also get all the MAC addresses of your ethernet cards along with all the IP addresses setup for each ethernet card. Information such as your Gateway, WINS server, DNS server, subnet mask, and all the IPs associated with your each NIC.An interesting way to discover what MAC addresses you know of other people on your network is to type ARP -a in a command prompt and you should get a listing that is similar to this.

Interface: 192.168.1.102 --- 0x2   Internet Address      Physical Address      Type   192.168.1.1           00-20-78-d9-5c-b3     dynamic   192.168.1.100         00-50-ba-b3-55-ec     dynamic   192.168.1.101         00-a0-cc-7a-7d-6d     dynamic

Leave a comment

Categories