![]() # Any values returned by platform.system() are valid. # This is useful when debugging issues or if you know a method # for a different platform works on the current platform. Getmac -ip 192.168.0.1 -override-port 9001 # The platform detected by getmac can be overridden via '-override-platform'. # Change the UDP port used for populating the ARP table when getting the MAC of a remote host # Debug levels can be specified with '-d' Python -m getmac -no-network-request -n home.router # This can be disabled with -no-network-request, as shown here: # By default, getmac will populate the table by sending a UDP packet to a high port on the host (defaults to 55555). # Getting the MAC address of a remote host requires the ARP table to be populated. # Running as a Python module with shorthands for the arguments # Interface names, IPv4/IPv6 addresses, or Hostnames can be specified # Invoking with no arguments will return MAC of the default interface Python 2 users: use getmac2 or python -m getmac instead of getmac. get_mac_address ( ip = "192.168.0.1", network_request = True )) Terminal examples PORT = 44444 # Default is 55555 print ( getmac. get_mac_address ( interface = "Ethernet 3" )) # Change the UDP port used for updating the ARP table (UDP packet) from getmac import getmac getmac. DEBUG = 2 # DEBUG level 2 print ( getmac. Python examples from getmac import get_mac_address eth_mac = get_mac_address ( interface = "eth0" ) win_mac = get_mac_address ( interface = "Ethernet 3" ) ip_mac = get_mac_address ( ip = "192.168.0.1" ) ip6_mac = get_mac_address ( ip6 = "::1" ) host_mac = get_mac_address ( hostname = "localhost" ) updated_mac = get_mac_address ( ip = "10.0.0.1", network_request = True ) # Enable debugging from getmac import getmac getmac. Stable release from PyPI pip install getmac If you want to use psutil, scapy, or netifaces, I have examples of how to do so in a GitHub Gist. In some cases it can be significantly faster. ![]() If the only system you need to run on is Linux, you can run as root, and C-extensions modules are fine, then you should instead check out the arpreq package by Sebastian Schrader. Another great option that fits these requirements is the well-known and battle-hardened psutil package by Giampaolo Rodola. However, unfortunately it is no longer maintained as of May 2021, so it may not be a great choice for new projects. If you only need the addresses of network interfaces, have a limited set of platforms to support, and are able to handle C-extension modules, then you should instead check out the excellent netifaces package by Alastair Houghton ( It's significantly faster (thanks to it being C-code) and has been around a long time and seen widespread usage. It provides one function: get_mac_address() ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |