blob: 5c28a5a7db110e1c06ad2b19d1c1d1f375a48d62 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
#!/usr/bin/env python3
from walu 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"]
|