[joker] add simple cli test and arp table support

This commit is contained in:
Ryabin Sergey 2013-10-31 16:22:25 +04:00
parent 7ae4a2a05f
commit d5d6df9b5d
2 changed files with 15 additions and 4 deletions

View File

@ -167,14 +167,20 @@ class Node():
return (stdout.readlines(), stderr.readlines())
def __discover__(self):
(data, _) = self.runCommand(
"ip link | awk -F: '/^[0-9]+?: eth/ {print $2}' |\
sudo xargs -I% arp-scan -l -I % 2>&1 | grep -E '^[0-9]+?\.'")
"(test -x arp-scan && ip link | awk -F: '/^[0-9]+?: eth/ {print $2}' |\
sudo xargs -I% arp-scan -l -I % 2>&1 | grep -E '^[0-9]+?\.';\
arp -an | awk -F\" \" '{ gsub(\"[^0-9\\.]\", \"\", $2); printf(\"%s\\t%s\\t%s\\n\", $2, $4, $7)}'\
)")
for line in data:
(ip, hwAddr, _) = line.strip().split("\t")
self.neighbours.append({"hwAddr": hwAddr, "ip": ip})
self.debugLog("%s -> %s" % (self.hostName, ip))
return self.neighbours

5
joker_test.py Normal file
View File

@ -0,0 +1,5 @@
from joker import Joker
j = Joker(None)
j.addNode("localhost", "127.0.0.1", 22, "root", "password")
print j.discover()