Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add client API, Readme and move server code.
- Loading branch information
Showing
10 changed files
with
115 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
This project aims to provide a simple way to get the description of an ASN, and | ||
to see the changes over the time. | ||
|
||
We use the data provided by cidr-report.org: | ||
http://www.cidr-report.org/as2.0/autnums.html | ||
|
||
Server | ||
====== | ||
|
||
Fetch ASNs descriptions from cidr-report.org, parse the HTML file and populate | ||
a redis database. | ||
|
||
Client | ||
====== | ||
|
||
Query this database to get the description(s) (latest or all). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Query a redis database to access to the ASNs descriptions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import api | ||
api.__prepare() | ||
|
||
from api import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import redis | ||
import dateutil.parser | ||
|
||
redis_host = '127.0.0.1' | ||
redis_db = 0 | ||
redis_port = 6389 | ||
|
||
r = None | ||
|
||
def __prepare(): | ||
global r | ||
if r is None: | ||
r = redis.Redis(host = redis_host, port=redis_port, db=redis_db) | ||
|
||
|
||
def get_all_descriptions(asn): | ||
""" | ||
Get all the descritpiosn available in the database for this ASN. | ||
Most recent first. | ||
[ | ||
(datetime.datetime(), 'description 1'), | ||
(datetime.datetime(), 'description 2'), | ||
... | ||
] | ||
""" | ||
all_descrs = r.hgetall(asn) | ||
dates = sorted(all_descrs.keys(), reverse=True) | ||
to_return = [] | ||
for date in dates: | ||
d = dateutil.parser.parse(date) | ||
to_return.append((d, all_descrs[date])) | ||
return to_return | ||
|
||
|
||
def get_last_description(asn): | ||
""" | ||
Get only the most recent description. | ||
""" | ||
all_descrs = r.hgetall(asn) | ||
if len(all_descrs) == 0: | ||
return None | ||
dates = sorted(all_descrs.keys()) | ||
return all_descrs[dates[-1]] | ||
|
||
def get_last_update(): | ||
last_update = r.get('last_update') | ||
if last_update is not None: | ||
return dateutil.parser.parse(last_update) | ||
return None | ||
|
||
def get_all_updates(): | ||
all_updates = sorted(r.smembers('all_timestamps'), reverse=True) | ||
if len(all_updates) == 0: | ||
return None | ||
to_return = [] | ||
for u in all_updates: | ||
to_return.append(dateutil.parser.parse(u)) | ||
return to_return | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
from distutils.core import setup | ||
|
||
try: | ||
from distutils.command.build_py import build_py_2to3 as build_py | ||
except ImportError: | ||
from distutils.command.build_py import build_py | ||
|
||
setup( | ||
name='asnhistory', | ||
version='1.0', | ||
description='Query a redis database to access to the ASNs descriptions.', | ||
url='https://github.com/Rafiot/ASN-Description-History', | ||
author='Raphaël Vinot', | ||
author_email='raphael.vinot@circl.lu', | ||
maintainer='Raphaël Vinot', | ||
maintainer_email='raphael.vinot@circl.lu', | ||
packages=['asnhistory'], | ||
cmdclass = {'build_py': build_py}, | ||
license='GNU GPLv3', | ||
long_description=open('README.md').read(), | ||
) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.