12/25/2023 0 Comments Get ip address from mac address linuxStable 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() Remote hosts on the local network (by IPv4/IPv6 address or hostname).System network interfaces (by interface name).It provides a platform-independent interface to get the MAC addresses of: If you want to put a little more effort in, and parse more data out, I recommend using the -online argument to the ip command, which will let you treat every line as a new device: $ ip -o linkġ: lo: mtu 16436 qdisc noqueue \ link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00Ģ: eth0: mtu 1500 qdisc pfifo_fast qlen 1000\ link/ether 00:0c:29:30:21:48 brd ff:ff:ff:ff:ff:ffģ: eth1: mtu 1500 qdisc pfifo_fast qlen 1000\ link/ether 00:0c:29:30:21:52 brd ff:ff:ff:ff:ff:ffĤ: tun0: mtu 1500 qdisc pfifo_fast qlen 100\ link/ĥ: sit0: mtu 1480 qdisc noop \ link/sit 0.0.0.0 brd 0.0.0.Pure-Python package to get the MAC address of network interfaces and hosts on the local network. You can trivially get the mac address from this output with awk: $ ip link show eth0 | awk '/ether/ ' I like using /sbin/ip for these kind of tasks, because it is far easier to parse: $ ip link show eth0Ģ: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |