From 949459a8d9ad824828b837d51b50401eb8ee9826 Mon Sep 17 00:00:00 2001 From: Alexandre Dulaunoy Date: Sun, 17 Feb 2019 09:57:26 +0100 Subject: [PATCH] chg: [lib] Ranking fixed using the default BGP Ranking client library BGP Ranking is now fixed and now using the default library provided by https://github.com/D4-project/BGP-Ranking --- DomainClassifier/domainclassifier.py | 35 ++++++++-------------------- requirements.txt | 1 + 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/DomainClassifier/domainclassifier.py b/DomainClassifier/domainclassifier.py index c6100d1..e268a56 100644 --- a/DomainClassifier/domainclassifier.py +++ b/DomainClassifier/domainclassifier.py @@ -8,6 +8,7 @@ import re import dns.resolver import IPy import socket +from datetime import date, timedelta try: #python 3 @@ -16,11 +17,14 @@ except: #python 2 import urllib2 as urllib - +try: + from pybgpranking import BGPRanking +except: + print ("pybgpranking is not installed - ranking of ASN values won't be possible") __author__ = "Alexandre Dulaunoy" -__copyright__ = "Copyright 2012-2017, Alexandre Dulaunoy" +__copyright__ = "Copyright 2012-2019, Alexandre Dulaunoy" __license__ = "AGPL version 3" -__version__ = "0.6" +__version__ = "0.7" class Extract: @@ -64,28 +68,9 @@ class Extract: """ def __bgpranking(self, asn=None): if asn: - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - s.connect((self.bgprankingserver, 43)) - s.send(asn+"\r\n") - r = '' - while True: - d = s.recv(2048) - r = r + d - if d == '': - break - s.close() - if len(r) > 0: - try: - rr = r.split("\n")[1].split(",") - except IndexError: - return None - if len(rr) > 1: - rank = rr[1] - return float(rank) - else: - return None - else: - return None + bgpranking = BGPRanking() + value = bgpranking.query(asn, date=(date.today() - timedelta(1)).isoformat()) + return value['response']['ranking']['rank'] def __updatelisttld(self): ianatldlist = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt" diff --git a/requirements.txt b/requirements.txt index 0e7f60b..bc95254 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ IPy dnspython +git+https://github.com/D4-project/BGP-Ranking.git/@7e698f87366e6f99b4d0d11852737db28e3ddc62#egg=pybgpranking&subdirectory=client