Using the getmac command (with examples)
- Windows
- November 5, 2023
The getmac command is a useful Windows command that allows you to display the MAC (Media Access Control) addresses of a system. MAC addresses are unique identifiers assigned to network devices, and this command can be helpful in network troubleshooting and management tasks.
In this article, we will explore different use cases of the getmac command and provide code examples for each case. Let’s get started!
Display the MAC addresses for the current system
To display the MAC addresses for the current system, you can simply use the following command:
getmac
Motivation: This is a basic use case of the getmac command that provides a quick way to view the MAC addresses of the network interfaces on the current system. It can be useful when you need to determine the MAC addresses for networking purposes or to verify the connectivity of your network devices.
No arguments are required for this use case. The command will automatically retrieve and display the MAC addresses of all enabled network interfaces on the current system.
Example output:
Physical Address Transport Name
=================== ==========================================================
52-54-00-12-34-56 \Device\Tcpip_{01234567-89ab-cdef-0123-456789abcdef}
Display the details in a specific format
To display the MAC addresses in a specific format, you can use the /fo
(format) option followed by the desired format. The available formats are table
, list
, and csv
. Here’s an example:
getmac /fo table
Motivation: This use case allows you to customize the output format of the MAC addresses. You can choose between a table format (table
), a list format (list
), or a comma-separated values format (csv
). This can be helpful when you need to extract specific information from the output or import it into other tools or scripts.
Explanation for the argument:
/fo
- Specifies the output format.table|list|csv
- Specifies the desired format for the output.
Example output (table format):
Physical Address Transport Name
=================== ==========================================================
52-54-00-12-34-56 \Device\Tcpip_{01234567-89ab-cdef-0123-456789abcdef}
Exclude the header in the output list
By default, the output of the getmac command includes a header row with column names. If you want to exclude the header from the output list, you can use the /nh
(no header) option. Here’s an example:
getmac /nh
Motivation: This use case is useful when you only need the MAC addresses and want to remove the header row from the output. It can be beneficial when you need to process the output programmatically or if you want a cleaner output for readability.
Explanation for the argument:
/nh
- Excludes the header from the output list.
Example output:
52-54-00-12-34-56 \Device\Tcpip_{01234567-89ab-cdef-0123-456789abcdef}
Display the MAC addresses for a remote machine
To display the MAC addresses for a remote machine, you can use the /s
(remote system) option followed by the hostname of the remote machine. Additionally, you may need to provide the credentials for accessing the remote machine using the /u
(username) and /p
(password) options. Here’s an example:
getmac /s hostname /u username /p password
Motivation: This use case allows you to retrieve the MAC addresses of network interfaces on a remote machine. It can be helpful in situations where you need to troubleshoot network connectivity issues or gather information about the network configuration of a remote system.
Explanation for the arguments:
/s
- Specifies the remote system’s hostname./u
- Specifies the username for authentication (if required)./p
- Specifies the password for authentication (if required).
Example output (assuming successful authentication):
Physical Address Transport Name
=================== ==========================================================
52-54-00-12-34-56 \Device\Tcpip_{01234567-89ab-cdef-0123-456789abcdef}
Display the MAC addresses with verbose information
To display the MAC addresses with verbose information, you can use the /v
(verbose) option. Here’s an example:
getmac /v
Motivation: This use case provides additional details about the network interfaces along with the MAC addresses. It includes information such as the network interface name, description, and device type. This can be helpful when you need a more detailed view of the network interfaces on the system.
No additional arguments are required for this use case. The command will retrieve and display the MAC addresses along with verbose information.
Example output:
Connection Name Network Adapter Physical Address Transport Name
================= ========================== =================== ============================
Ethernet Intel(R) 82579LM Gigabit 52-54-00-12-34-56 \Device\Tcpip_{01234567-89ab-cdef-0123-456789abcdef}
Network Connection
Display detailed usage information
Finally, if you need to get detailed usage information for the getmac command, you can use the /?
option. Here’s an example:
getmac /?
Motivation: This use case is useful when you want to review all available options, arguments, and examples for using the getmac command. It provides a comprehensive help menu that explains how to use the command effectively.
No additional arguments are required for this use case. The command will display detailed usage information for the getmac command.
Example output (partial):
Displays the local and remote MAC (Media Access Control) addresses
of a network adapter.
...
Usage: getmac [/s Computer [/u [Domain\]User /p Password]] [/fo {table|list|csv}] [/nh] [/v] [/?]
...
Conclusion
The getmac command is a versatile Windows command that allows you to retrieve the MAC addresses of network interfaces on a system. By exploring different use cases and learning how to use various options and arguments, you can leverage the power of this command for network troubleshooting and management tasks.
Remember to refer to the provided examples for guidance and consult the official documentation for more information on using the getmac command effectively.