diff options
author | krebs <krebs@UTART> | 2011-05-22 01:42:36 +0200 |
---|---|---|
committer | krebs <krebs@UTART> | 2011-05-22 01:42:36 +0200 |
commit | 951d398e20fdb778289e7dff2350594503dc300f (patch) | |
tree | a52b4a8bcd57f70def4ead7529ad4c9c66eab386 /modules/people/arping_users.py | |
parent | 0ec6ff898460d767cf984d792949ba7344e0758b (diff) |
updated people script,
removed bloat from people script collection
Diffstat (limited to 'modules/people/arping_users.py')
-rwxr-xr-x | modules/people/arping_users.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/modules/people/arping_users.py b/modules/people/arping_users.py new file mode 100755 index 00000000..c576e4f3 --- /dev/null +++ b/modules/people/arping_users.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +import subprocess,re,logging,sys + +from arping import arpingy +from multiprocessing import Pool +DEV='eth0' +MAC_NAMES='mac_names.lst' +data = [] +ret = {} +verb = False + +if len(sys.argv) > 1 and sys.argv[1] == 'v': + verb = True +def get_own_addr(): + data = subprocess.Popen(['/sbin/ifconfig',DEV], + stdout=subprocess.PIPE).communicate()[0].replace('\n','') + return re.sub(r'.*HWaddr ([0-9A-Fa-f:]*).*inet addr:([0-9.]*).*' , + r'\1 \2',data).split() + +def load_names(MAC_NAMES): + names = {} + f = open(MAC_NAMES) + for l in f: + mac,name = l.split() + names[mac] = name.replace('\n','') + f.close() + return names + +def arping_helper(dic): + return arpingy(**dic) + +for first in range(4): + for second in range(255): + data.append({'iprange':'10.42.'+str(first)+'.'+str(second),'iface':DEV}) + +names = load_names(MAC_NAMES) +try: + p = Pool(20) + ret = filter(lambda x:x , p.map(arping_helper, data)) + myip,mymac = get_own_addr() + ret.append([mymac,myip]) + p.terminate() +except Exception as e: + print 'you fail '+str(e) + + + +for p in ret: + if verb: + print p[0] + " => " + p[1] + if p[1] in names: + print names[p[1]]+ " is online" + + |