Added RIPE Live bgp
This commit is contained in:
parent
fd14433603
commit
685d8ccca5
26
examples/bgp.py
Normal file
26
examples/bgp.py
Normal file
@ -0,0 +1,26 @@
|
||||
import pybgpstream
|
||||
from collections import defaultdict
|
||||
|
||||
def fetch_asn_ip_mappings():
|
||||
asn_ip_mappings = defaultdict(list)
|
||||
stream = pybgpstream.BGPStream(
|
||||
project="ris-live",
|
||||
filter="collector rrc00",
|
||||
)
|
||||
for rec in stream:
|
||||
for elem in rec:
|
||||
if elem.type == "A":
|
||||
origin_asn = elem.fields["as-path"].split()[-1]
|
||||
prefix = elem.fields["prefix"]
|
||||
if prefix not in asn_ip_mappings[origin_asn]:
|
||||
asn_ip_mappings[origin_asn].append(prefix)
|
||||
print(f'{origin_asn} - {prefix}')
|
||||
return asn_ip_mappings
|
||||
|
||||
if __name__ == "__main__":
|
||||
mappings = fetch_asn_ip_mappings()
|
||||
for asn, prefixes in mappings.items():
|
||||
print(f"ASN: {asn}, Prefixes: {', '.join(prefixes)}")
|
||||
|
||||
|
||||
|
25
examples/ris-live.js
Normal file
25
examples/ris-live.js
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
Subscribe to a RIS Live stream and output every message to the javascript console.
|
||||
|
||||
The exact same code will work in Node.js after running 'npm install ws' and including the following line:
|
||||
|
||||
const WebSocket = require('ws');
|
||||
*/
|
||||
var ws = new WebSocket("wss://ris-live.ripe.net/v1/ws/?client=js-example-1");
|
||||
var params = {
|
||||
moreSpecific: true,
|
||||
host: "rrc21",
|
||||
socketOptions: {
|
||||
includeRaw: true
|
||||
}
|
||||
};
|
||||
ws.onmessage = function(event) {
|
||||
var message = JSON.parse(event.data);
|
||||
console.log(message.type, message.data);
|
||||
};
|
||||
ws.onopen = function() {
|
||||
ws.send(JSON.stringify({
|
||||
type: "ris_subscribe",
|
||||
data: params
|
||||
}));
|
||||
};
|
26
ris-live.py
Normal file
26
ris-live.py
Normal file
@ -0,0 +1,26 @@
|
||||
import json
|
||||
|
||||
try:
|
||||
import websocket
|
||||
except ImportError:
|
||||
raise SystemExit('missing websocket-client')
|
||||
|
||||
ws = websocket.WebSocket()
|
||||
ws.connect('wss://ris-live.ripe.net/v1/ws/?client=bgpexample')
|
||||
|
||||
params = {
|
||||
'moreSpecific': True,
|
||||
'host': 'rrc21',
|
||||
'socketOptions': {
|
||||
'includeRaw': True
|
||||
}
|
||||
}
|
||||
|
||||
ws.send(json.dumps({
|
||||
'type': 'ris_subscribe',
|
||||
'data': params
|
||||
}))
|
||||
|
||||
for data in ws:
|
||||
parsed = json.loads(data)
|
||||
print(parsed['type'], parsed['data'])
|
Loading…
Reference in New Issue
Block a user