From e0ec5d2e8560ae433ee677622b24ba82dbe7630b Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 29 May 2011 15:47:21 +0200 Subject: lowered filesystem hierarchy--everything are modules --- census/arping_users.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 census/arping_users.py (limited to 'census/arping_users.py') diff --git a/census/arping_users.py b/census/arping_users.py new file mode 100755 index 00000000..c576e4f3 --- /dev/null +++ b/census/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" + + -- cgit v1.2.3 From ad89350b16a31d6bd6a644ad162d8723e85945ee Mon Sep 17 00:00:00 2001 From: root Date: Thu, 30 Jun 2011 01:05:00 +0200 Subject: updated people script mac_names updated with more names --- census/arping_users.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'census/arping_users.py') diff --git a/census/arping_users.py b/census/arping_users.py index c576e4f3..008fe337 100755 --- a/census/arping_users.py +++ b/census/arping_users.py @@ -21,7 +21,7 @@ def load_names(MAC_NAMES): names = {} f = open(MAC_NAMES) for l in f: - mac,name = l.split() + mac,name = l.split(' ',1) names[mac] = name.replace('\n','') f.close() return names @@ -29,7 +29,7 @@ def load_names(MAC_NAMES): def arping_helper(dic): return arpingy(**dic) -for first in range(4): +for first in range(1,3): for second in range(255): data.append({'iprange':'10.42.'+str(first)+'.'+str(second),'iface':DEV}) @@ -50,5 +50,3 @@ for p in ret: print p[0] + " => " + p[1] if p[1] in names: print names[p[1]]+ " is online" - - -- cgit v1.2.3 From a20bfbf919b5ccdd60cce008dd9c0bbe23ba1606 Mon Sep 17 00:00:00 2001 From: makefu Date: Sun, 31 Jul 2011 04:28:03 +0200 Subject: arping_users.py: replaced verbose with quiet flag --- census/arping_users.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'census/arping_users.py') diff --git a/census/arping_users.py b/census/arping_users.py index 008fe337..ec3557d4 100755 --- a/census/arping_users.py +++ b/census/arping_users.py @@ -7,10 +7,10 @@ DEV='eth0' MAC_NAMES='mac_names.lst' data = [] ret = {} -verb = False +quiet=False -if len(sys.argv) > 1 and sys.argv[1] == 'v': - verb = True +if len(sys.argv) > 1 and sys.argv[1] == 'q': + quiet=True def get_own_addr(): data = subprocess.Popen(['/sbin/ifconfig',DEV], stdout=subprocess.PIPE).communicate()[0].replace('\n','') @@ -46,7 +46,7 @@ except Exception as e: for p in ret: - if verb: + if not quiet: print p[0] + " => " + p[1] if p[1] in names: print names[p[1]]+ " is online" -- cgit v1.2.3 From 3d12232fe37fa3f6279e7c7ee5258f7a67f3bc58 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 6 Aug 2011 00:19:21 +0200 Subject: people: extended range --- census/arping_users.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'census/arping_users.py') diff --git a/census/arping_users.py b/census/arping_users.py index ec3557d4..934f9bea 100755 --- a/census/arping_users.py +++ b/census/arping_users.py @@ -29,8 +29,8 @@ def load_names(MAC_NAMES): def arping_helper(dic): return arpingy(**dic) -for first in range(1,3): - for second in range(255): +for first in range(1,4): + for second in range(256): data.append({'iprange':'10.42.'+str(first)+'.'+str(second),'iface':DEV}) names = load_names(MAC_NAMES) -- cgit v1.2.3 From 67331f023a364d8e256c848ea42467d2ad870e47 Mon Sep 17 00:00:00 2001 From: makefu Date: Sat, 6 Aug 2011 01:55:58 +0200 Subject: refactored arping_users, needs some working --- census/arping_users.py | 61 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 21 deletions(-) (limited to 'census/arping_users.py') diff --git a/census/arping_users.py b/census/arping_users.py index ec3557d4..5866c517 100755 --- a/census/arping_users.py +++ b/census/arping_users.py @@ -3,9 +3,13 @@ import subprocess,re,logging,sys from arping import arpingy from multiprocessing import Pool +logging.basicConfig(level=logging.DEBUG) +log = logging.getLogger("main") DEV='eth0' MAC_NAMES='mac_names.lst' data = [] +my_addr = False +my_names = {} ret = {} quiet=False @@ -17,36 +21,51 @@ def get_own_addr(): return re.sub(r'.*HWaddr ([0-9A-Fa-f:]*).*inet addr:([0-9.]*).*' , r'\1 \2',data).split() -def load_names(MAC_NAMES): +def load_names(mac_file): names = {} - f = open(MAC_NAMES) + f = open(mac_file) for l in f: mac,name = l.split(' ',1) names[mac] = name.replace('\n','') f.close() return names +def print_config(): + log.info("My Addr : %s" %str(my_addr)) + log.info("MAC Names file: %s " %MAC_NAMES) + log.debug("Loaded names : ") + for mac,name in my_names.iteritems(): + log.debug("%s => %s" %(mac,name)) +def init(): + my_addr = get_own_addr() + my_names = load_names(MAC_NAMES) -def arping_helper(dic): - return arpingy(**dic) +def main(): + init() + print_config() + exit(0) + def arping_helper(dic): + return arpingy(**dic) -for first in range(1,3): - for second in range(255): - data.append({'iprange':'10.42.'+str(first)+'.'+str(second),'iface':DEV}) + for first in range(1,3): + 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) + 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 not quiet: - print p[0] + " => " + p[1] - if p[1] in names: - print names[p[1]]+ " is online" + for p in ret: + if not quiet: + print p[0] + " => " + p[1] + if p[1] in names: + print names[p[1]]+ " is online" +if __name__ == "__main__": + log.debug("starting arping_users") + main() -- cgit v1.2.3