get_mac_address()
psutil
, scapy
, or netifaces
, I have examples of how to doso in a GitHub Gist.getmac2
or python -m getmac
instead of getmac
.interface
: Name of a network interface on the systemip
: IPv4 address of a remote hostip6
: IPv6 address of a remote hosthostname
: Hostname of a remote hostnetwork_request
: If an network request should be made to updateand populate the ARP/NDP table of remote hosts used to lookup MACsin most circumstances. Disable this if you want to just use what'salready in the table, or if you have requirements to prevent networktraffic. The network request is a empty UDP packet sent to a highport, 55555 by default. This can be changed by setting getmac.PORT
to the desired integer value. Additionally, on Windows, this willsend a UDP packet to 1.1.1.1:53 to attempt to determine the default interface.logging.getLogger('getmac')
: Runtime messages and errors are recorded to the getmac
logger using the logging
module. They can be configured by using logging.basicConfig()
or adding handlers to the getmac
logger.getmac.getmac.DEBUG
: integer value that controls debugging output. The higher the value, the more output you get.getmac.getmac.PORT
: UDP port used to populate the ARP/NDP table(see the documentation of the network_request
argument in get_mac_address()
for details)getmac
that supported that version.The wheels are available in theGitHub releases, orfrom PyPI with a current version of pip
and some special arguments.network_request
does not have any functionality when the interface
argument isspecified, and can be safely set if using in a script.getmac.exe
, ipconfig.exe
, arp.exe
, wmic.exe
uuid
, ctypes
, socket
arp
, ip
, ifconfig
, netstat
, ip link
, lanscan
uuid
, fcntl
, socket
/sys/class/net/{iface}/address
, /proc/net/arp
/proc/net/route
, route
, ip route list
networksetup
ifconfig
, arp
route
ifconfig
, arp
netstat
getmac -4 10.0.0.4
will fail if 10.0.0.4
is the IP address of a local interface).This issue may be present on other POSIX systems as well.network_request
is enabled. If not, Ethernet
is used as the default.urllib
, ipaddress
, ftplib
, telnetlib
, ssl
, and more.Imagine my surprise, then, when I discovered there was not a way to get aseemingly simple piece of information: a MAC address. This package was bornout of a need to get the MAC address of hosts on the network withoutneeding admin permissions, and a cross-platform way get the addressesof local interfaces.getmac
from get-mac
. Thisaffected the package name, the CLI script, and some of the documentation.There were no changes to the core library code. While both package nameswill updated on PyPI, the use of getmac
is preferred.getmac<1
. I will continue to fix reported bugs and accept patches for the last release before 1.0.0, however active development will cease and new features will not be backported.arping
as last resortvulture
, several Flake8 pluginsip
or ip6
were used,which could lead to a ResourceWarning
(GH-42)print
(logger: getmac
)--no-network-requests
: -N
and --no-net
-v
/--verbose
RuntimeWarning
pytest
netifaces
, psutil
, scapy
, and arpreq
).This should improve the performance of lookups of non-existent interfacesor hosts, since this feature was punishing that path without providing much value.If you want to use these packages directly, I have a guide on how to do so on aGitHub Gist.warnings
module will only be imported if a error/warningoccurs (improve compatibility with some freezers, notably PyInstaller)pytest
for all tests now instead of unittest
network_request
is enabled (Credit: @cyberhobbes)getmac
. This applies to thecommand line tool, GitHub, and the documentation.__future__
getmac.getmac.DEBUG
.argparse
if Python version is 2.6 or olderarp
arpreq
packagewmic nic
get_mac_address(ip='10.0.0.100')
was 1.71 seconds.Now, the average is 12.7 miliseconds
, with the special case of a unpopulatedarp table being only slightly higher. This was brought about by changes inhow the arp table is populated. The original method was to use thehost's ping
command to send an ICMP packet to the host. This took time,which heavily delayed the ability to actually get an address. The solutionis to instead simply send a empty UDP packet to a high port. The portthis packet is sent to can be configured using the module variable getmac.PORT
.getmac.py
psutil
: Interface MACs on all platformsscapy
: Interface MACs and Remote MACs on all platformsnetifaces
: Interface MACs on Non-Windows platformsip neighbor show
, Abuse of uuid._arp_getnode()
lanscan -ai
(HP-UX)ip6
argument (IPv6 addresses)proc/net/arp
would return shorter addresses in thesame subnet if they came earlier in the sequence. Example: a search for192.168.16.2
on Linux would instead return the MAC address of192.168.16.254
with no errors or warning whatsoever.ip
or route
commands available, or thenetifaces
Python module.--debug
-d
option from --no-network-requests
get-mac
python -m getmac
arp_request
argument was renamed to network_request
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size getmac-0.8.2-py2.py3-none-any.whl (24.3 kB) | File type Wheel | Python version py2.py3 | Upload date | Hashes |
Filename, size getmac-0.8.2.tar.gz (47.6 kB) | File type Source | Python version None | Upload date | Hashes |
Algorithm | Hash digest |
---|---|
SHA256 | 2e4aef2dd6c3befccd7cf9e18badddd24ab1992b928e2e811d415ed47137c547 |
MD5 | 0041377c3fb7b48dd8eb0418db29854e |
BLAKE2-256 | 306973ce4e89c5444dea22b490d70ba4bccef4877691904dd211019fda765b35 |
Algorithm | Hash digest |
---|---|
SHA256 | d501d20b71856248cfa07a8758192e86a01077910afb8b659a89946c4d52d368 |
MD5 | cf1af0d5c0e5d1fe7f62401bcb726a26 |
BLAKE2-256 | 60a2d64aed61f8f86827eab2e77e49a6158630690daa8130f7452a4b676acefc |