Skip to content

Commit

Permalink
added support for whois for ninux names
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardomaccari committed Sep 26, 2015
1 parent a423411 commit 3e712a9
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
21 changes: 21 additions & 0 deletions netdiff/mywhois.py
@@ -0,0 +1,21 @@
import socket


def whois(query, hostname="chi.ninux.org"):
""" Perform a basic whois request, from
http://code.activestate.com/recipes/577364-whois-client/ """
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((hostname, 43))
s.send(query + "\r\n")
response = ''
while True:
d = s.recv(4096)
response += d
if not d:
break
s.close()
fields = {}
for line in response.split('\n'):
if "mapserver:" in line:
fields["mapserver"] = line.replace(' ', '').split(":")[1]
return fields
7 changes: 6 additions & 1 deletion netdiff/parsers/base.py
Expand Up @@ -2,6 +2,7 @@
import json
import requests
import telnetlib
from ..mywhois import whois

try:
import urlparse
Expand Down Expand Up @@ -146,7 +147,11 @@ def json(self, dict=False, **kwargs):
self.version,
self.revision,
self.metric,
graph.nodes(),
graph.nodes(data=True),
graph.edges(data=True),
dict,
**kwargs)

def resolveIPs(self):
for n in self.graph:
self.graph.node[n]["label"] = whois(n)["mapserver"]
11 changes: 8 additions & 3 deletions netdiff/utils.py
Expand Up @@ -22,14 +22,14 @@ def diff(old, new):
# or assign None if no changes
if added_nodes.nodes() and added_edges.edges():
added = _netjson_networkgraph(protocol, version, revision, metric,
added_nodes.nodes(),
added_nodes.nodes(data=True),
added_edges.edges(data=True),
dict=True)
else:
added = None
if removed_nodes.nodes() and removed_edges.edges():
removed = _netjson_networkgraph(protocol, version, revision, metric,
removed_nodes.nodes(),
removed_nodes.nodes(data=True),
removed_edges.edges(data=True),
dict=True)
else:
Expand Down Expand Up @@ -129,7 +129,12 @@ def _netjson_networkgraph(protocol, version, revision, metric,
if metric is None and protocol != 'static':
raise NetJsonError('metric cannot be None except when protocol is "static"')
# prepare lists
node_list = [{'id': node} for node in nodes]
node_list = []
for node in nodes:
attrs = {'id': node[0]}
for key, val in node[1].items():
attrs[key] = val
node_list.append(attrs)
link_list = []
for link in links:
link_list.append(OrderedDict((
Expand Down

0 comments on commit 3e712a9

Please sign in to comment.