Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am ytti on github.
  • I am ytti (https://keybase.io/ytti) on keybase.
  • I have a public key whose fingerprint is 91F0 68C8 5A1C 0C10 1AE0 BE2B E870 F16A 810A E277

To claim this, I am signing this object:

@ytti
ytti / spf.rb
Last active December 11, 2015 12:20
ruby SPF/Dijkstra implementation
#!/usr/bin/env ruby
## Example run: (omitting DST will show cost+path to all dsts)
## [ytti@eng0.dllstx09.us.to.gin.ntt.net ~/git/misc]% ./spf.rb r23.snjsca04.us.bb r20.frnkge04.de.bb
## ---
## r20.frnkge04.de.bb:
## cost: 155152
## path:
## - r23.snjsca04.us.bb
## - r22.snjsca04.us.bb
@ytti
ytti / getLatency.rb
Created December 10, 2015 08:31
get ISIS neighbours and their latencies
#!/usr/bin/env ruby
# this requires ruby2.0, if important I'll package this
require 'pty'
require 'expect'
require 'ipaddr'
require 'json'
require 'pry'
require 'pp'
@ytti
ytti / getTopology.rb
Created December 10, 2015 12:06
builds IGP topology off JNPR
#!/usr/bin/env ruby
require 'ntt/junos/xmlssh'
require 'pry'
class GetTopology
HOST = 'r00.testtx09.us.bb'
COMMAND = 'show isis database detail'
attr_reader :nodes, :edges
@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
@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 / 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 / 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 / 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 / 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'