Skip to content

Instantly share code, notes, and snippets.

@marek22k
Created May 30, 2022 17:59
Show Gist options
  • Save marek22k/494cf9c4d269867f23f2c3577e1780ef to your computer and use it in GitHub Desktop.
Save marek22k/494cf9c4d269867f23f2c3577e1780ef to your computer and use it in GitHub Desktop.
Calculates the prefix assigned to the ASN based on the ASN.
# see https://explorer.dn42.dev/#/inet6num/fde0:93fa:7a0:2::_64
if ! ARGV[0]
puts "arg 0 is the asn"
end
asn = ARGV[0]
asn_bin = asn.to_i.to_s(2)
asn_low16 = asn_bin[0...16].to_i(2).to_s(16)
asn_high16 = asn_bin[16..-1].to_i(2).to_s(16)
puts "ASN: #{asn}"
puts "Subnet is fde0:93fa:7a0:2::/64"
puts "For the AS usable subnet: fde0:93fa:7a0:2:0:#{asn_low16}:#{asn_high16}:/112"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment