summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts
diff options
context:
space:
mode:
authormakefu <root@pigstarter.de>2013-06-24 14:01:33 +0200
committermakefu <root@pigstarter.de>2013-06-24 14:01:33 +0200
commitd5751b4a5132522b38c611e6bfd79537e927db50 (patch)
treef86a2285e1290307271a9a9209098a2210c918dd /retiolum/scripts
parent4b957b0dd4a60e22b66c5547e0d4a62b3763953b (diff)
nodes_geoip : initial commit
Diffstat (limited to 'retiolum/scripts')
-rwxr-xr-xretiolum/scripts/adv_graphgen/nodes_geoip.py26
1 files changed, 26 insertions, 0 deletions
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)