Query the Kernel ARP cache for the MAC address corresponding to IP address
Python C extension to query the Kernel ARP cache for the MAC address of a given IP address.
The arpreq module exposes a single function arpreq, that will resolve a given IPv4 address into a MAC address.
An IP address can only be resolved to a MAC address if it is on the same subnet as your machine.
Let’s assume your current machine has the address 192.168.1.10 and another machine with the address 192.168.1.1 is on the same subnet:
>>> import arpreq >>> arpreq.arpreq('192.168.1.1') '00:11:22:33:44:55'
If a IP address can not be resolved to an MAC address, None is returned.
>>> arpreq.arpreq('188.8.131.52') is None True
IP addresses may be also be specified as int or rich IP address data type of the common ipaddr, ipaddress, or netaddr modules.
>>> arpreq.arpreq(0x7F000001) '00:00:00:00:00:00' >>> import netaddr >>> arpreq.arpreq(netaddr.IPAddress('127.0.0.1')) '00:00:00:00:00:00' >>> import ipaddr # on Python 2 >>> arpreq.arpreq(ipaddr.IPv4Address('127.0.0.1')) '00:00:00:00:00:00' >>> import ipaddress >>> arpreq.arpreq(ipaddress.IPv4Address(u'127.0.0.1')) '00:00:00:00:00:00'
This extension has only been tested on Linux, it should however work on any platform that supports the SIOCGARP ioctl, which is virtually every BSD, Linux and Mac OS.
- Disable PEP-489 on PyPy3
- Disable PyModule_GetState on PyPy3
- Provide a Debian package
- Support point-to-point veth pairs (See #6)
- Accept unicode objects on Python 2 and bytes objects on Python 3 (See #5)
- Some test improvements
- Don’t use private _PyErr_ChainExceptions (breaks on Debian Jessie)
- Use PEP 489 multi-phase extension module initialization on Python 3.5+
- Close socket if module initialization failed
- Code cleanup
- Fix memset overflow
- Provide Python wheels
- Support int and rich IP address objects as IP address arguments
- Release the GIL during arpreq
- Add units tests
- Rework MAC string creation
- Restructure module initialization
- Initial release
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.