new: Display IPs
parent
0fab47248d
commit
078f775d4c
|
@ -5,6 +5,7 @@ from typing import TypeVar
|
||||||
import datetime
|
import datetime
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from redis import StrictRedis
|
from redis import StrictRedis
|
||||||
|
@ -77,6 +78,19 @@ class Querying():
|
||||||
return descriptions
|
return descriptions
|
||||||
return descriptions[sorted(descriptions.keys(), reverse=True)[0]]
|
return descriptions[sorted(descriptions.keys(), reverse=True)[0]]
|
||||||
|
|
||||||
|
def get_prefix_ips(self, asn: int, prefix: str, date: Dates=datetime.date.today(), source: str=''):
|
||||||
|
if source:
|
||||||
|
sources = [source]
|
||||||
|
else:
|
||||||
|
sources = self.get_sources(date)
|
||||||
|
prefix_ips = defaultdict(list)
|
||||||
|
d = self.__normalize_date(date)
|
||||||
|
for source in sources:
|
||||||
|
ips = set([ip_ts.split('|')[0]
|
||||||
|
for ip_ts in self.storage.smembers(f'{d}|{source}|{asn}|{prefix}')])
|
||||||
|
[prefix_ips[ip].append(source) for ip in ips]
|
||||||
|
return prefix_ips
|
||||||
|
|
||||||
def get_asn_history(self, asn: int, period: int=100, source: str='', ipversion: str='v4'):
|
def get_asn_history(self, asn: int, period: int=100, source: str='', ipversion: str='v4'):
|
||||||
to_return = []
|
to_return = []
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
|
|
|
@ -9,7 +9,6 @@ from flask_bootstrap import Bootstrap
|
||||||
from bgpranking.querying import Querying
|
from bgpranking.querying import Querying
|
||||||
from datetime import date, timedelta
|
from datetime import date, timedelta
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
app.secret_key = '\xeb\xfd\x1b\xee\xed<\xa5~\xd5H\x85\x00\xa5r\xae\x80t5@\xa2&>\x03S'
|
app.secret_key = '\xeb\xfd\x1b\xee\xed<\xa5~\xd5H\x85\x00\xa5r\xae\x80t5@\xa2&>\x03S'
|
||||||
|
@ -18,6 +17,15 @@ Bootstrap(app)
|
||||||
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
|
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
|
||||||
|
|
||||||
|
|
||||||
|
def get_request_parameter(parameter):
|
||||||
|
if request.method == 'POST':
|
||||||
|
d = request.form
|
||||||
|
elif request.method == 'GET':
|
||||||
|
d = request.args
|
||||||
|
|
||||||
|
return d.get(parameter, None)
|
||||||
|
|
||||||
|
|
||||||
def load_session():
|
def load_session():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
d = request.form
|
d = request.form
|
||||||
|
@ -57,12 +65,19 @@ def asn_details():
|
||||||
load_session()
|
load_session()
|
||||||
q = Querying()
|
q = Querying()
|
||||||
ranks = q.asn_details(**session)
|
ranks = q.asn_details(**session)
|
||||||
return render_template('asn.html', ranks=ranks, **session)
|
prefix = get_request_parameter('prefix')
|
||||||
|
if prefix:
|
||||||
|
prefix_ips = q.get_prefix_ips(prefix=prefix, **session)
|
||||||
|
prefix_ips = [(ip, sorted(sources)) for ip, sources in prefix_ips.items()]
|
||||||
|
prefix_ips.sort(key=lambda entry: len(entry[1]), reverse=True)
|
||||||
|
else:
|
||||||
|
prefix_ips = []
|
||||||
|
return render_template('asn.html', ranks=ranks, prefix_ips=prefix_ips, **session)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/asn_history', methods=['GET', 'POST'])
|
@app.route('/asn_history', methods=['GET', 'POST'])
|
||||||
def asn_history():
|
def asn_history():
|
||||||
load_session()
|
load_session()
|
||||||
session.pop('date')
|
session.pop('date', None)
|
||||||
q = Querying()
|
q = Querying()
|
||||||
return json.dumps(q.get_asn_history(**session))
|
return json.dumps(q.get_asn_history(**session))
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
{% block head %}
|
{% block head %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
<link rel="stylesheet" href="{{ url_for('static', filename='linegraph.css') }}">
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,6 +16,7 @@
|
||||||
<center>
|
<center>
|
||||||
<h1>Ranking - {{asn}}</h1></br></br>
|
<h1>Ranking - {{asn}}</h1></br></br>
|
||||||
</center>
|
</center>
|
||||||
|
{% include ['top_forms.html'] %}
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Prefix</th>
|
<th>Prefix</th>
|
||||||
|
@ -24,10 +24,24 @@
|
||||||
</tr>
|
</tr>
|
||||||
{% for prefix, rank in ranks %}
|
{% for prefix, rank in ranks %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ prefix }}</td>
|
<td><a href="{{ url_for('asn_details', asn=asn, prefix=prefix) }}">{{ prefix }}</a></td>
|
||||||
<td>{{ rank }}</td>
|
<td>{{ rank }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
<canvas width="960" height="500"></canvas>
|
<canvas width="960" height="500"></canvas>
|
||||||
|
{% if prefix_ips %}
|
||||||
|
<table class="table">
|
||||||
|
<tr>
|
||||||
|
<th>IP</th>
|
||||||
|
<th>Source(s)</th>
|
||||||
|
</tr>
|
||||||
|
{% for ip, sources in prefix_ips %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ ip }}</td>
|
||||||
|
<td>{{ ', '.join(sources) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</table>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -6,35 +6,7 @@
|
||||||
<center>
|
<center>
|
||||||
<h1>BGP Ranking</h1></br></br>
|
<h1>BGP Ranking</h1></br></br>
|
||||||
</center>
|
</center>
|
||||||
<p>
|
{% include ['top_forms.html'] %}
|
||||||
<form style="width:300px; display:inline-block;" action="" method=post>
|
|
||||||
<input name="date" type="date" value="{{ date }}">
|
|
||||||
<input type="submit" value="Set date">
|
|
||||||
</form>
|
|
||||||
<form style="width:300px; display:inline-block;" action="" method=post>
|
|
||||||
<select name="ipversion">
|
|
||||||
<option value="v4" {% if ipversion == 'v4' %} selected="selected"{% endif %}>v4</option>
|
|
||||||
<option value="v6" {% if ipversion == 'v6' %} selected="selected"{% endif %}>v6</option>
|
|
||||||
</select>
|
|
||||||
<input type="submit" value="Set IP version">
|
|
||||||
</form>
|
|
||||||
<form style="width:300px; display:inline-block;" action="" method=post>
|
|
||||||
<select name="source">
|
|
||||||
<option value="" {% if not source %} selected="selected"{% endif %}>all</option>
|
|
||||||
{% for s in sources %}
|
|
||||||
<option value="{{ s }}" {% if source == s %} selected="selected"{% endif %}>{{ s }}</option>
|
|
||||||
{% endfor %}
|
|
||||||
</select>
|
|
||||||
<input type="submit" value="Set source">
|
|
||||||
</form>
|
|
||||||
<p>
|
|
||||||
|
|
||||||
<br/>
|
|
||||||
<form action="{{ url_for('asn_details') }}" method=post>
|
|
||||||
ASN to search: <input type=number name=asn>
|
|
||||||
<input type="submit" value="Search">
|
|
||||||
</form>
|
|
||||||
<br/>
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>ASN</th>
|
<th>ASN</th>
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<p>
|
||||||
|
<form style="width:300px; display:inline-block;" action="" method=post>
|
||||||
|
<input name="date" type="date" value="{{ date }}">
|
||||||
|
<input type="submit" value="Set date">
|
||||||
|
</form>
|
||||||
|
<form style="width:300px; display:inline-block;" action="" method=post>
|
||||||
|
<select name="ipversion">
|
||||||
|
<option value="v4" {% if ipversion == 'v4' %} selected="selected"{% endif %}>v4</option>
|
||||||
|
<option value="v6" {% if ipversion == 'v6' %} selected="selected"{% endif %}>v6</option>
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="Set IP version">
|
||||||
|
</form>
|
||||||
|
<form style="width:500px; display:inline-block;" action="" method=post>
|
||||||
|
<select name="source">
|
||||||
|
<option value="" {% if not source %} selected="selected"{% endif %}>all</option>
|
||||||
|
{% for s in sources %}
|
||||||
|
<option value="{{ s }}" {% if source == s %} selected="selected"{% endif %}>{{ s }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
<input type="submit" value="Set source">
|
||||||
|
</form>
|
||||||
|
<form style="width:500px; display:inline-block;" action="{{ url_for('asn_details') }}" method=post>
|
||||||
|
ASN to search: <input type=number name=asn>
|
||||||
|
<input type="submit" value="Search">
|
||||||
|
</form>
|
||||||
|
<p>
|
||||||
|
<br/>
|
Loading…
Reference in New Issue