From 102429b18255f0364426fd377ac988c3d4624e6f Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sun, 11 Feb 2024 15:58:43 +0530 Subject: repo: init --- src/walu/arp.py | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/walu/arp.py (limited to 'src/walu/arp.py') diff --git a/src/walu/arp.py b/src/walu/arp.py new file mode 100644 index 0000000..82f8445 --- /dev/null +++ b/src/walu/arp.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import names + +class arp: + table = {} + + def __init__(self): + self.refresh() + + @staticmethod + def flag_to_status(flag): + flagmap = { + "0x0" : "offline", + "0x2" : "online", + "0x6" : "manual", + } + + try: + status = flagmap[flag] + except: + return "chilling with penguin" + else: + return status + + def refresh(self): + self.table = {} + + with open("/proc/net/arp") as f: + f.readline() # skip table header + + + for line in f: + row = line.split() + + ip = row[0] + flag = row[2] + mac = row[3] + dev = row[5] + + name = names.iptoname(ip) + if not name: + name = names.mactoname(mac) + if not name: + name = "Anon" + + self.table[ip] = { + "name" : name, + "mac" : mac, + "dev" : dev, + "status" : self.flag_to_status(flag), + } + + def ip_to_status(self, ip): + try: + status = self.table[ip] + except: + pass + else: + return status + + def ip_to_mac(self, ip): + try: + tab = self.table[ip] + except: + pass + else: + return tab["mac"] -- cgit v1.2.3