Skip to content

Instantly share code, notes, and snippets.

View digizeph's full-sized avatar
🌟

Mingwei Zhang digizeph

🌟
View GitHub Profile
use std::io::Cursor;
use rdkafka::{ClientConfig, ClientContext, Message};
use rdkafka::consumer::{CommitMode, Consumer, ConsumerContext, StreamConsumer};
pub use bgpkit_parser::{parse_bmp_msg, parse_openbmp_header};
use log::{info, error};
// A simple context to customize the consumer behavior and print a log line every time
// offsets are committed
struct LoggingConsumerContext;
use bgpkit_parser::BgpkitParser;
fn main() {
let url =
"http://archive.routeviews.org/bgpdata/\
2021.10/UPDATES/updates.20211001.0000.bz2";
for elem in BgpkitParser::new(url) {
println!("{:?}|{:?}|{:?}|{:?}|{:?}",
elem.elem_type,
elem.timestamp,
{
"data": {
"count": 5,
"current_page": 1,
"items": [
{
"collector_id": "route-views.amsix",
"data_type": "update",
"timestamp": 1633362300,
"url": "http://archive.routeviews.org/route-views.amsix/bgpdata/2021.10/UPDATES/updates.20211004.1545.bz2"
@digizeph
digizeph / bgpkit-parser-example-1.rs
Created November 1, 2021 05:07
BGPKIT Parser remote file parsing example.
use bgpkit_parser::BgpkitParser;
fn main() {
let url =
"http://archive.routeviews.org/bgpdata/\
2021.10/UPDATES/updates.20211001.0000.bz2";
for elem in BgpkitParser::new(url) {
println!("{:?}|{:?}|{:?}|{:?}|{:?}",
elem.elem_type,
elem.timestamp,
@digizeph
digizeph / parse-multiple.rs
Created October 23, 2021 23:00
Parse multiple files using BGPKIT Parser and Broker
use std::io::BufReader;
use bzip2::read::BzDecoder;
use bgpkit_parser::{BgpElem, BgpkitParser};
/// This example shows how use BGPKIT Broker to retrieve a number of data file pointers that matches
/// the time range criteria, and then parse the data files for each one.
///
/// The dependency needed for this example are:
/// ```
/// bzip2="0.4"
@digizeph
digizeph / Dockerfile
Created June 18, 2021 16:57
Two-stage build for Rust project with need for ssl libraries (such as an web api)
LABEL maintainer="YOUR NAME <YOUR@EMAIL>"
# select build image
FROM rust:1.52 as build
# create a new empty shell project
RUN USER=root cargo new --bin my_project
WORKDIR /my_project
# if you need nightly
# change toolchain to nightly for rocket
@digizeph
digizeph / updates.txt
Created June 2, 2021 21:17
BGP announcements made by AS55410 originating an Apple (AS714)'s IP block 17.29.115.0/24 on 2021-06-02
➜ ~ bgpreader -k 17.29.115.0/24 -w 1622664000,1622665200 -a 55410 --record-type updates 2>/dev/null
U|A|1622664887.000000|ris|rrc12|||57695|80.81.192.231|17.29.115.0/24|80.81.192.231|57695 60068 33891 6461 9498 55410 55410 55410|55410|57695:13000||
U|A|1622664891.000000|ris|rrc03|||205206|193.239.117.18|17.29.115.0/24|193.239.117.18|205206 33891 6461 9498 55410 55410 55410|55410|33891:33893 33891:33896 33891:40071||
U|A|1622664917.000000|ris|rrc03|||205206|193.239.117.18|17.29.115.0/24|193.239.117.18|205206 33891 6461 9498 55410 55410 55410|55410|33891:33893 33891:33896 33891:40071||
U|A|1622664925.000000|ris|rrc20|||31424|91.206.52.17|17.29.115.0/24|91.206.52.17|31424 33891 6461 9498 55410 55410 55410|55410|33891:33893 33891:33896 33891:40071 31424:1150||
U|A|1622664927.000000|ris|rrc05|||47692|193.203.0.192|17.29.115.0/24|193.203.0.192|47692 33891 6461 9498 55410 55410 55410|55410|33891:33893 33891:33896 33891:40071 47692:30000 47692:30140||
U|A|1622664928.000000|ris|rrc12|||47692|80.81.194.100|17.29.115.0
@digizeph
digizeph / gist:3d77739a8289beeafbb06eb71b585baf
Created February 22, 2021 13:21
193.53.37.0/24 MOAS 2021-02-22
❯ bgpreader -w'2021-02-22 11:00','2021-02-22 13:00' -k 193.53.37.0/24 -t updates -c rrc00|grep 194.28.98.37
U|W|1613992145.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24||||||
U|A|1613992145.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24|194.28.98.37|34872 39533 29396 39686|39686|0:39533 39533:49666||
U|A|1613992164.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24|194.28.98.37|34872 24961 3257 174 39686|39686|24961:1 24961:8108 24961:9002||
U|A|1613992168.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24|194.28.98.37|34872 24961 3257 174 39686|39686|24961:1 24961:8108 24961:9002||
U|W|1613992169.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24||||||
U|A|1613992169.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24|194.28.98.37|34872 39533 35625 29396 39686|39686|0:39533 35625:29396 35625:64512 39533:49666 51706:64601 51706:64650 51706:65011 51706:65023||
U|A|1613992194.000000|ris|rrc00|||34872|194.28.98.37|193.53.37.0/24|194.28.98.37|34872 39533 13030 1299 174 39686|39686|0:39533 1299
@digizeph
digizeph / gist:8f99fd3d4a9166cbe11e9029628be074
Last active February 5, 2021 20:45
BGP messages during BGP leak event against a Twitter prefix on Feb. 5th, 2021
update|A|1612537210.000000|ris|rrc11|None|None|24482|198.32.160.242|104.244.42.0/24|198.32.160.242|24482 13414 13414|24115:65023 24115:13414 24482:65302 24482:13021 24482:13020 24482:2|None|None
update|A|1612537237.000000|routeviews|route-views.telxatl|None|None|27446|198.32.132.160|104.244.42.0/24|198.32.132.160|27446 27446 13414 13414||None|None
update|A|1612537714.000000|ris|rrc03|None|None|208627|193.239.118.142|104.244.42.0/24|193.239.118.142|208627 43350 13414 13414||None|None
update|A|1612538393.000000|ris|rrc12|None|None|42861|80.81.195.167|104.244.42.0/24|80.81.195.167|42861 13414 13414|42861:2300 42861:3000 6777:65023 6777:65011|None|None
update|A|1612538432.000000|ris|rrc07|None|None|20764|194.68.123.188|104.244.42.0/24|194.68.123.188|20764 13414 13414|20764:3000 20764:3033 20764:3020 6777:65023 6777:65011 20764:3014|None|None
update|A|1612539329.053464|routeviews|route-views.eqix|None|None|199524|206.126.237.22|104.244.42.0/24|206.126.237.22|199524 13414 13414||None|None
update|A|1612539329.067115
@digizeph
digizeph / emacs-installation.org
Last active September 10, 2022 14:59
Emacs 27 and Doom Emacs Setup Guide

Emacs 27 and Doom Emacs Setup Guide

Goal

Build Emacs 27 from source code and install Doom Emacs

Install Emacs

Checkout sourcecode