I'm trying to make a program that is able to, upon start, read the arp cache for the router (with its mac, ip etc) and then echo (or just write) it into a file. Then later when a particular event occurs, read the data and compare current cache with the previous. Anybody know the code to read the cache in python? (I'm working on a linux machine in case that matters)
First install python_arptable
:
pip install python_arptable
Then in your script :
from python_arptable import get_arp_table
print(get_arp_table())
It should return something like :
[{'Mask': '*', 'HW address': 'xx:xx:xx:xx:xx:xx', 'IP address': 'xxx.xxx.xx.xxx', 'HW type': '0x1', 'Flags': '0x2', 'Device': 'wlp2s0'}, {'Mask': '*', 'HW address': 'xx:xx:xx:xx:xx:xx', 'IP address': 'xxx.xxx.xxx.xxx', 'HW type': '0x1', 'Flags': '0x2', 'Device': 'wlp2s0'}]