Skip to content

Instantly share code, notes, and snippets.

@digizeph
Created November 13, 2021 06:03
Show Gist options
  • Select an option

  • Save digizeph/940706c774f73a15c1824bc8a728e755 to your computer and use it in GitHub Desktop.

Select an option

Save digizeph/940706c774f73a15c1824bc8a728e755 to your computer and use it in GitHub Desktop.
RIS Live stream Facebook example
use bgpkit_parser::parse_ris_live_message;
use serde_json::json;
use tungstenite::{connect, Message};
use url::Url;
use bgpkit_parser::parser::ElemType;
const RIS_LIVE_URL: &str = "ws://ris-live.ripe.net/v1/ws/?client=rust-bgpkit-parser";
/// This is an example of subscribing to RIS-Live's streaming data from one host (`rrc21`).
///
/// For more RIS-Live details, check out their documentation at https://ris-live.ripe.net/manual/
fn main() {
// connect to RIPE RIS Live websocket server
let (mut socket, _response) =
connect(Url::parse(RIS_LIVE_URL).unwrap())
.expect("Can't connect to RIS Live websocket server");
// subscribe to messages from one collector
let msg = json!({"type": "ris_subscribe", "data": {"host": "rrc21"}}).to_string();
socket.write_message(Message::Text(msg)).unwrap();
loop {
let msg = socket.read_message().expect("Error reading message").to_string();
if let Ok(elems) = parse_ris_live_message(msg.as_str()) {
for elem in elems {
if let Some(origins) = elem.origin_asns.as_ref() {
if origins.contains(&32934) &&
( elem.prefix.to_string() == "129.134.30.0/23".to_string() ||
elem.prefix.to_string() == "185.89.218.0/23".to_string() )
{
println!("{}", elem);
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment