new: Display IPs
parent
0fab47248d
commit
078f775d4c
|
@ -5,6 +5,7 @@ from typing import TypeVar
|
|||
import datetime
|
||||
from datetime import timedelta
|
||||
from dateutil.parser import parse
|
||||
from collections import defaultdict
|
||||
|
||||
import logging
|
||||
from redis import StrictRedis
|
||||
|
@ -77,6 +78,19 @@ class Querying():
|
|||
return descriptions
|
||||
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'):
|
||||
to_return = []
|
||||
today = datetime.date.today()
|
||||
|
|
|
@ -9,7 +9,6 @@ from flask_bootstrap import Bootstrap
|
|||
from bgpranking.querying import Querying
|
||||
from datetime import date, timedelta
|
||||
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
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
|
||||
|
||||
|
||||
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():
|
||||
if request.method == 'POST':
|
||||
d = request.form
|
||||
|
@ -57,12 +65,19 @@ def asn_details():
|
|||
load_session()
|
||||
q = Querying()
|
||||
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'])
|
||||
def asn_history():
|
||||
load_session()
|
||||
session.pop('date')
|
||||
session.pop('date', None)
|
||||
q = Querying()
|
||||
return json.dumps(q.get_asn_history(**session))
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
{% block head %}
|
||||
{{ super() }}
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='linegraph.css') }}">
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
@ -17,6 +16,7 @@
|
|||
<center>
|
||||
<h1>Ranking - {{asn}}</h1></br></br>
|
||||
</center>
|
||||
{% include ['top_forms.html'] %}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Prefix</th>
|
||||
|
@ -24,10 +24,24 @@
|
|||
</tr>
|
||||
{% for prefix, rank in ranks %}
|
||||
<tr>
|
||||
<td>{{ prefix }}</td>
|
||||
<td><a href="{{ url_for('asn_details', asn=asn, prefix=prefix) }}">{{ prefix }}</a></td>
|
||||
<td>{{ rank }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<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 %}
|
||||
|
|
|
@ -6,35 +6,7 @@
|
|||
<center>
|
||||
<h1>BGP Ranking</h1></br></br>
|
||||
</center>
|
||||
<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: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/>
|
||||
{% include ['top_forms.html'] %}
|
||||
<table class="table">
|
||||
<tr>
|
||||
<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