diff options
author | root <root@krebs> | 2011-08-06 02:06:20 +0200 |
---|---|---|
committer | root <root@krebs> | 2011-08-06 02:06:20 +0200 |
commit | 29547aff1bea7bdfdb71072d3aeb35d5dad94c5b (patch) | |
tree | 456e2385c4cd9299ed8b89f850c4d204c0650e94 /census | |
parent | d7a46958ec661c3024ff20a469a824fdd0d3d5fa (diff) | |
parent | 4ba5f6f8bf321c4c1f1c0f5652248fbbc2cd2419 (diff) |
Merge branch 'master' of github.com:/krebscode/painload
Diffstat (limited to 'census')
-rwxr-xr-x | census/arping_users.py | 55 |
1 files changed, 37 insertions, 18 deletions
diff --git a/census/arping_users.py b/census/arping_users.py index 934f9bea..f0df4924 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,4): for second in range(256): 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() |