1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
#!/usr/local/bin/nexp
#
if {$argc < 2} {
puts "Usage: $argv0 <input file> <output file> \[PCAP filter]"
exit 1
}
set infile [lindex $argv 0]
set outfile [lindex $argv 1]
set filter ""
if {$argc == 3} {
set filter [lindex $argv 0]
}
set npackets 0
spawn_network -r $infile -w $outfile $filter
expect_network {1} {
send_network data(data = '$_(packet)')
# send_network ether(src = $eth(src), dst = $eth(dst) )/ \
# ip(id = $ip(id), src = $ip(src), dst = $ip(dst), \
# tcp(flags = $tcp(flags), seq = $tcp(seq), ack-seq = $tcp(ack), \
# window = $tcp(window_size), src = $tcp(srcport), \
# dst = $tcp(dstport) )/raw($raw)
incr npackets
nexp_continue
} eof {
# It is necessary to have an "eof" case to be able to exit the
# expect_network statement because select() will always say that a
# file descriptor is ready to be read on end-of-file. In other words
# in the case of end-of-file, select() will never timeout, so we
# can't rely on a timeout to take us out of the expect_network
# statement. No "eof" case will mean an infinite loop in the
# expect_network statement.
}
close_network nexp0
puts "$npackets packets processed."
|