Created
October 28, 2014 10:52
-
-
Save meise/6aa543f66290a1005f68 to your computer and use it in GitHub Desktop.
Create subnet to asn csv mapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget http://thyme.apnic.net/current/data-used-autnums | |
wget http://data.ris.ripe.net/rrc03/latest-bview.gz | |
bgpdump latest-bview.gz | ruby bgpdump_to_asn.rb data-used-autnums |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# encoding: UTF-8 | |
# Input format provided by bgpdump | |
# TIME: 10/27/14 16:00:00 | |
# TYPE: TABLE_DUMP_V2/IPV4_UNICAST | |
# PREFIX: 1.52.176.0/20 | |
# SEQUENCE: 1128 | |
# FROM: 80.249.208.111 AS30132 | |
# ORIGINATED: 10/17/14 14:02:53 | |
# ORIGIN: IGP | |
# ASPATH: 30132 3491 18403 | |
# NEXT_HOP: 80.249.209.37 | |
# Usage: bgpdump latest-bview.gz | ruby bgpdump_to_asn.rb data-used-autnums > asn_db.csv | |
prefix, asn, send_prefixes, as_number_to_as_name = '', '', {}, {} | |
File.open(ARGV[0], 'r:iso-8859-1').each_line do |line| | |
match = /^\s*(\d+)\s*(.*)$/.match(line) | |
as_number_to_as_name[match[1]] = match[2] | |
end | |
while(STDIN.gets) | |
case $_ | |
when /^PREFIX:\s+(.*?)$/ | |
prefix = $1 | |
when /^ASPATH:\s(.*?)$/ | |
asn = $1.split.last | |
when /^\s+$/ | |
unless send_prefixes[prefix] | |
puts "#{prefix};#{asn};#{as_number_to_as_name[asn]}" | |
send_prefixes[prefix] = true | |
end | |
else | |
next | |
end | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment