Skip to content

Instantly share code, notes, and snippets.

@ytti
ytti / cvm.rb
Last active May 19, 2024 07:21
#!/usr/bin/env ruby
## CVM is algorithm to estimate amount of unique items in list of items. It is so simple and cheap that
## it could reasonably be implemented in silicon, so that cheap switches and routers could report fps or flows
## per second counter in addition to bps and pps. Understanding total flow count allows you to do understand
## statistical probability and confidence in your ability to reason from ipfix sampled data, if you don't know
## your total flow count, you don't know what share of flows you see, and most things cannot be reasoned from ipfix
## My implementation almost certainly is wrong, as I don't understand the paper, and Quanta version is wrong
## - https://arxiv.org/abs/2301.10191
## - https://www.cs.toronto.edu/~meel/Slides/meel-distinct.pdf
@ytti
ytti / gdns.rb
Created July 8, 2021 15:32
CLI UX to Google Cloud DNS
#!/usr/bin/env ruby
require "google/cloud/dns"
require "commander"
#require "pry"
#
class GDNS
PROJECT = "resonant-petal-318815"
AUTH = File.join(Dir.home, ".config", "google_cloud_sdk_auth.json")
TTL = 1800
@ytti
ytti / gist:7829e8484378c9b50d162555ee3eb8f1
Created March 18, 2018 13:11
Automated contributor contract verification
Problem statement: You require that your contributors sign a contract, perhaps to relinquish the copyright, perhaps to accept the licensing terms. This disincentivizes contributing due to creating barrier of entry.
Paid repositories could have opt-in feature for 'approved contributors only'. If repository owner has opted-in, then every pull request signature is verified to come from pre-approved developer. If pull request is not from appreved developer the developer is presented with a process to become approved developer.
The process starts with a web page where developer writes personal string or draws personal picture, after that is done, the web page queries for an email address and then repsents random string used for signature later.
After the email arrives to a developer, developer clicks on the URL and is directed to a web page, which presents the personal string or personal picture and developer is asked if they made it. If they answer 'yes', they are presented with terms of agreement, if they acce
@ytti
ytti / pcapop
Last active March 15, 2018 12:39
script to offer unified API to pcap and pcapng, and to pop N bytes out of each captured file (useful to remove e.g. ERSPAN monitoring headers)
#!/usr/bin/env ruby
require "logger"
require "stringio"
class PCAPop
class Error < StandardError; end
class InvalidFormat < Error; end
class ByteOrderError < Error; end
@ytti
ytti / sppcapture.rb
Created November 18, 2016 09:18
Turn IOS-XR SPP/NETIO capture into an PCAP
#!/usr/bin/env ruby
## 1) ssh asr9k | tee spp.capture
## 2) do spp/netio capture in asr9k
## 3) ./sppcapture.rb spp.capture
## 4) text2pcap spp.capture.packet spp.capture.pcap
## 5) open spp.capture.pcap
class SPPCapture
FILE_EXTENSION = 'packet'
@ytti
ytti / netmonte.cr
Created September 23, 2016 13:25
Crystal version of Monte Carlo simulation on when two networks or more networks fail together and for how many minutes (how robust does OOB network need to be, to have reasonable probability that both networks are not down at the same time)
module NetMonte
STANDARD_DEVIATION = 2.5
MINUTES = 365*24*60
class Simulate
def initialize(years, *networks)
years.times do |year|
nets = init_networks networks
roulette year, nets
@ytti
ytti / netmonte.rb
Created September 23, 2016 12:45
Monte Carlo simulation on when two networks or more networks fail together and for how many minutes (how robust does OOB network need to be, to have reasonable probability that both networks are not down at the same time)
#!/usr/bin/env ruby
module NetMonte
STANDARD_DEVIATION = 2.5
MINUTES = 365*24*60
class Simulate
def initialize years, *networks
years.times do |year|
@ytti
ytti / brute_ip_checksum.rb
Last active August 24, 2016 12:23
script to figure out what bits need to be flipped to get specific checksum on an IP header
#!/usr/bin/env ruby
# your IP header
DATA = [0x4501, 0x0028, 0x87ea, 0x4000, 0x3006, 0x5bfd, 0xXXXX, 0xXXXX, 0xXXXX, 0xXXXX]
IS = DATA[5] # checksum on the packet
WANT = 0x5bfc # checksum you want
# output
# (here we can see that packet had ECN bit set, but had it not had, checksum would be correct)
@ytti
ytti / jnh_exception_packet_trace.rb
Last active August 22, 2022 11:56
script to turn JunOS Trio exception capture into a PCAP
#!/usr/bin/env ruby
# script to generate PCAP from Trio exception trace. Potentially you may need to change POP_BYTES variable.
# Trio exception trace allows you to capture things like broken packets (checksum error), to see who is sending them
# clogin junos-trio-box | tee exception_trace
# start shell pfe network fpc0
# show jnh 0 exceptions terse
# debug jnh exceptions N discard ## get N from above command
# debug jnh exceptions-trace
@ytti
ytti / xr2pcap.rb
Last active January 18, 2021 01:52
XR NPU counter to pcap
#!/usr/bin/env ruby
## 1) capture data => monitor np counter MDF_PUNT_POLICE_DROP np0 count 25 location 0/2/CPU0
##
## 2) You'll need 'text2pcap' => sudo apt-get install wireshark-common
##
## 3) Run with file as argument:
## [ytti@lintukoto ~/tmp/ios-xr-npu-monitor-pcap]% ./xr2pcap.rb r04.miamfl02.us.bb.MDF_PUNT_POLICE_DROP.ioscap
## Input from: r04.miamfl02.us.bb.MDF_PUNT_POLICE_DROP.txt
## Output to: r04.miamfl02.us.bb.MDF_PUNT_POLICE_DROP.pcap