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
This commit is contained in:
Alexandre Dulaunoy 2019-02-17 09:57:26 +01:00
parent 12e57efc4c
commit 949459a8d9
Signed by: adulau
GPG key ID: 09E2CD4944E6CBCD
2 changed files with 11 additions and 25 deletions

View file

@ -8,6 +8,7 @@ import re
import dns.resolver import dns.resolver
import IPy import IPy
import socket import socket
from datetime import date, timedelta
try: try:
#python 3 #python 3
@ -16,11 +17,14 @@ except:
#python 2 #python 2
import urllib2 as urllib 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" __author__ = "Alexandre Dulaunoy"
__copyright__ = "Copyright 2012-2017, Alexandre Dulaunoy" __copyright__ = "Copyright 2012-2019, Alexandre Dulaunoy"
__license__ = "AGPL version 3" __license__ = "AGPL version 3"
__version__ = "0.6" __version__ = "0.7"
class Extract: class Extract:
@ -64,28 +68,9 @@ class Extract:
""" """
def __bgpranking(self, asn=None): def __bgpranking(self, asn=None):
if asn: if asn:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) bgpranking = BGPRanking()
s.connect((self.bgprankingserver, 43)) value = bgpranking.query(asn, date=(date.today() - timedelta(1)).isoformat())
s.send(asn+"\r\n") return value['response']['ranking']['rank']
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
def __updatelisttld(self): def __updatelisttld(self):
ianatldlist = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt" ianatldlist = "https://data.iana.org/TLD/tlds-alpha-by-domain.txt"

View file

@ -1,2 +1,3 @@
IPy IPy
dnspython dnspython
git+https://github.com/D4-project/BGP-Ranking.git/@7e698f87366e6f99b4d0d11852737db28e3ddc62#egg=pybgpranking&subdirectory=client