From d5751b4a5132522b38c611e6bfd79537e927db50 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 24 Jun 2013 14:01:33 +0200 Subject: nodes_geoip : initial commit --- retiolum/scripts/adv_graphgen/nodes_geoip.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 retiolum/scripts/adv_graphgen/nodes_geoip.py (limited to 'retiolum/scripts') diff --git a/retiolum/scripts/adv_graphgen/nodes_geoip.py b/retiolum/scripts/adv_graphgen/nodes_geoip.py new file mode 100755 index 00000000..7f12d213 --- /dev/null +++ b/retiolum/scripts/adv_graphgen/nodes_geoip.py @@ -0,0 +1,26 @@ +#!/usr/bin/python3 +# -*- coding: utf8 -*- +import sys,json + +def delete_unused_nodes(nodes): + new_nodes = {} + for k,v in nodes.iteritems(): + if v['external-ip'] == "(null)": + continue + if v.get('to',[]): + new_nodes[k] = v + for k,v in new_nodes.iteritems(): + if not [ i for i in v['to'] if i['name'] in new_nodes]: + #del(new_nodes[k]) + del(k) + return new_nodes + +if __name__ == "__main__": + from pygeoip import GeoIP + gi = GeoIP("GeoLiteCity.dat") + for node,data in delete_unused_nodes(json.load(sys.stdin)).items(): + + try: + print ("%s in %s"%(node,gi.record_by_addr(data["external-ip"])["city"])) + except: + print ("%s myself"%node) -- cgit v1.2.3