Created
November 18, 2016 09:18
-
-
Save ytti/ab33dfb235302eabe6ec6165e143fff6 to your computer and use it in GitHub Desktop.
Turn IOS-XR SPP/NETIO capture into an PCAP
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 | |
## 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' | |
PACKET_START = /length \d+ phys_int_index \d+ next_ctx/ | |
PACKET_END = /^------/ | |
POP_BYTES = 72 | |
def self.to_ascii_file file | |
file_base = File.basename(file) | |
file_ext = File.extname(file) | |
ext = FILE_EXTENSION | |
ext += '2' if file_ext == FILE_EXTENSION | |
file_output = [file_base, ext].join '.' | |
trace = new File.read(file) | |
File.write file_output, trace.to_packets | |
puts "packet written in '#{file_output}'" | |
puts "run 'text2pcap #{file_output} #{file_base}.pcap' to generate pcap file" | |
end | |
def initialize data | |
@packets = parse_data data | |
end | |
def to_packets | |
str = "" | |
@packets.each do |packet| | |
str << "000000 " + packet[POP_BYTES..-1].join(" ") + "\n" | |
end | |
str | |
end | |
def parse_data data | |
packets = [] | |
packet = [] | |
in_packet = false | |
data.each_line do |line| | |
next if not in_packet and not line.match PACKET_START | |
if line.match PACKET_START | |
in_packet = true | |
next | |
end | |
if line.match PACKET_END | |
in_packet = false | |
packets << packet | |
packet = [] | |
next | |
end | |
_offset, packet_data = line.strip.split ":" | |
packet += packet_data.split | |
end | |
packets | |
end | |
end | |
begin | |
if $0 == __FILE__ | |
SPPCapture.to_ascii_file(ARGV.first) | |
end | |
rescue => error | |
warn error.message | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment