-
Notifications
You must be signed in to change notification settings - Fork 15
/
sc_warts2text.py
executable file
·63 lines (58 loc) · 2 KB
/
sc_warts2text.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
#
# Program: $Id: $
# Author: Robert Beverly <[email protected]>
# Description: Replicate output of scamper's sc_warts2text
import sys
from sc_stats import WartsStats, basic, obj_type
def print_trace(flags, ips, rtts, meta):
print "traceroute from %s to %s" % (flags['srcaddr'], flags['dstaddr'])
for i, ip in enumerate(ips):
ttl = i+1
print "%2d %s" % (ttl, ip),
if ttl in rtts:
print " %2.3f ms" % (rtts[ttl]),
if ttl in meta:
for v in meta[ttl]:
print "%s" % (v),
print
def print_ping(flags, responses):
rtts = []
print "ping %s to %s: %d byte packets" % (flags['srcaddr'], flags['dstaddr'], flags['size'])
rcount = set()
for response in responses:
rcount.add(response['probeid'])
rtt = response['rtt']/1000.0
rtts.append(rtt)
print "%d bytes from %s, seq=%d ttl=%d time=%3.3f ms" % \
(response['replysize'], response['addr'], response['probeid'],
response['replyttl'], rtt)
print "--- %s ping statistics ---" % flags['dstaddr']
loss = 100.0 - (len(rcount) * 100.0 / flags['psent'])
print "%d packets transmitted, %d packets received, %d%% packet loss" % \
(flags['psent'], len(rcount), loss)
if len(rcount) > 0:
print "round-trip min/avg/max/stddev = %2.3f/%2.3f/%2.3f/%2.3f ms" % \
basic(rtts)
if __name__ == "__main__":
assert len(sys.argv) >= 2
target = None
if len(sys.argv) == 3: target = sys.argv[2]
w = WartsStats(sys.argv[1], verbose=False)
while True:
try:
(typ, data) = w.next()
if typ == None:
break
elif typ == obj_type['TRACE']:
(flags, ips, rtts, meta) = data
if target and target != flags['dstaddr']: continue
print_trace(flags, ips, rtts, meta)
elif typ == obj_type['PING']:
(flags, responses) = data
if target and target != flags['dstaddr']: continue
print_ping(flags, responses)
except Exception, e:
print "Flags:", flags
print "** Error:", e
sys.exit(-1)