diff options
author | makefu <github@syntax-fehler.de> | 2013-01-14 14:46:22 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2013-01-14 14:46:22 +0100 |
commit | dbe2d838ba6834788265029162b2dd7d82473335 (patch) | |
tree | a4eb38f7fc91d91269b6f83453de62242c6ddc23 /retiolum/scripts/adv_graphgen/find_super.py | |
parent | 5a782f6c8f7923f9f415afd504ce6e71acbc7fef (diff) | |
parent | abf9916bc1add17888308877fa4eb9da330297ef (diff) |
Merge branch 'master' of github.com:krebscode/painload
Conflicts:
god/temper/Makefile
god/temper/collectd-temper.sh
Diffstat (limited to 'retiolum/scripts/adv_graphgen/find_super.py')
-rw-r--r-- | retiolum/scripts/adv_graphgen/find_super.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/retiolum/scripts/adv_graphgen/find_super.py b/retiolum/scripts/adv_graphgen/find_super.py new file mode 100644 index 00000000..df01734e --- /dev/null +++ b/retiolum/scripts/adv_graphgen/find_super.py @@ -0,0 +1,50 @@ +#!/usr/bin/python + +def find_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 check_super(path="/etc/tinc/retiolum/hosts"): + from socket import socket,AF_INET,SOCK_STREAM + for host,addrs in find_super(path): + valid_addrs = [] + for addr in addrs: + try: + s = socket(AF_INET,SOCK_STREAM) + s.settimeout(3) + s.connect(addr) + #print("success connecting %s:%d"%(addr)) + s.settimeout(None) + s.close() + valid_addrs.append(addr) + except Exception as e: + pass + #print("cannot connect to %s:%d"%(addr)) + if valid_addrs: yield (host,valid_addrs) + + +if __name__ == "__main__": + """ + usage + """ + for host,addrs in check_super(): + print host,addrs |