diff options
author | makefu <github@syntax-fehler.de> | 2013-04-04 10:14:27 +0200 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2013-04-04 10:14:27 +0200 |
commit | 5266540d4c21494adbac3f25f982f2bf32390734 (patch) | |
tree | e0532270da21fbb368c98347c0506ed850d86e58 /retiolum/scripts/adv_graphgen | |
parent | 7fa8fb85b072f612adb322f8a02617e1bd737020 (diff) | |
parent | c57300f04afe66c596b6ea658457aae260ab323e (diff) |
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'retiolum/scripts/adv_graphgen')
-rw-r--r-- | retiolum/scripts/adv_graphgen/find-all-nodes.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/retiolum/scripts/adv_graphgen/find-all-nodes.py b/retiolum/scripts/adv_graphgen/find-all-nodes.py new file mode 100644 index 00000000..ae0fae8f --- /dev/null +++ b/retiolum/scripts/adv_graphgen/find-all-nodes.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +def find_potential_super(path="/etc/tinc/retiolum/hosts"): + import os + import re + + needle_addr = re.compile("Address\s*=\s*(.*)") + needle_port = re.compile("Port\s*=\s*(.*)") + for f in os.listdir(path): + with open(path+"/"+f) as of: + addrs = [] + port = "655" + + for line in of.readlines(): + + addr_found = needle_addr.match(line) + if addr_found: + addrs.append(addr_found.group(1)) + + port_found = needle_port.match(line) + if port_found: + port = port_found.group(1) + + if addrs : yield (f ,[(addr ,int(port)) for addr in addrs]) + +def try_connect(addr): + try: + from socket import socket,AF_INET,SOCK_STREAM + s = socket(AF_INET,SOCK_STREAM) + s.settimeout(2) + s.connect(addr) + s.settimeout(None) + s.close() + return addr + except Exception as e: + pass + #return () + +def check_one_super(ha): + host,addrs = ha + valid_addrs = [] + for addr in addrs: + ret = try_connect(addr) + if ret: valid_addrs.append(ret) + if valid_addrs: return (host,valid_addrs) + +def check_all_the_super(path="/etc/tinc/retiolum/hosts"): + from multiprocessing import Pool + p = Pool(20) + return filter(None,p.map(check_one_super,find_potential_super(path))) + + + +if __name__ == "__main__": + """ + usage + """ + for host,addrs in check_all_the_super(): + print host,addrs |