summaryrefslogtreecommitdiffstats
path: root/wrappers/traceproto
blob: 988fdc5f377d756cb22b876482871b4c19f619c5 (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
#
#   Copyright (c)  2007             Dmitry K. Butskoy
#                                   <buc@citadel.stu.neva.ru>
#   License:  GPL v2 or any later
#
#   See COPYING for the status of this software.
#

#
#  Shell wrapper providing traceproto(8) command line interface.
#
#  The original implementation of traceproto(8) can be obtained
#  from http://traceproto.sourceforge.net/
#


prgname=$0
opts=""
length=""
method="tcp"
sendwait=100
cont=""
iface=$TP_DEFAULT_IF


usage () {
    echo "Usage: $prgname [-cCTfAhvR] [-p protocol] [-d dst_port] [-D max_dst_port]
	[-s src_port] [-S max_src_port] [-m min_ttl] [-M max_ttl] [-w response_timeout]
	[-W send_delay] [-a account_level] [-P payload_size]
	[-F interface] [-k skips] [-I consecutive_trace_count]
	[-H packets_per_hop] [-i incr_pattern] [-o output_style] [-t tcp_flags]
	target" >&2
}

warning () {
    echo "$prgname: Option '$1' is not implemented in this wrapper" >&2
}
 

PARSED=`getopt 'cCTfAhvRp:d:D:s:S:m:M:w:W:a:P:F:k:I:H:i:o:t:' "$@"`
[ $? != 0 ] && exit 2

eval set -- "$PARSED"

while [ $# -gt 0 ]
do
    case "$1" in
	-p)  method=$2; shift 2 ;;
	-d)  opts="$opts -p $2"; shift 2 ;;
	-s)  opts="$opts --sport=$2"; shift 2 ;;
	-m)  opts="$opts -f $2"; shift 2 ;;
	-M)  opts="$opts -m $2"; shift 2 ;;
	-w)  opts="$opts -w $2"; shift 2 ;;
	-W)  sendwait=$2; shift 2 ;;
	-P)  length=$2; shift 2 ;;
	-c)  cont=100000; shift ;;
	-I)  cont=$2; shift 2 ;;
	-H)  opts="$opts -q $2"; shift 2 ;;
	-f)  opts="$opts -F"; shift ;;
	-F)  iface=$2; shift 2 ;;
	-A)  opts="$opts -A"; shift ;;
	-o)  [ $2 != "c" ] && warning $1; shift 2 ;;
	-t)  case $2 in
		*S*)  opts="$opts -O syn" ;;
	     esac
	     case $2 in
		*A*)  opts="$opts -O ack" ;;
	     esac
	     case $2 in
		*R*)  opts="$opts -O rst" ;;
	     esac
	     case $2 in
		*U*)  opts="$opts -O urg" ;;
	     esac
	     case $2 in
		*P*)  opts="$opts -O psh" ;;
	     esac
	     case $2 in
		*F*)  opts="$opts -O fin" ;;
	     esac
	     case $2 in
		*E*)  opts="$opts -O ece" ;;
	     esac
	     case $2 in
		*C*)  opts="$opts -O cwr" ;;
	     esac
	     shift 2 ;;
	-[DSaki])  warning $1; shift 2 ;;
	-[TCR])  warning $1; shift ;;
	-h)  usage; exit 0 ;;
	-v)  echo "\"traceproto\"-compatible wrapper for new Linux Traceroute" >&2;
	     exit 0 ;;
	--)  shift; break ;;
	*)  echo "$prgname: Internal parsing error" >&2; exit 2 ;;
    esac
done



[ $# -eq 0 ] && {
    usage
    exit 2
}

host=$1


opts="-M $method $opts"
opts="$opts -z $sendwait"
[ -n "$iface" ] && opts="$opts -i $iface"

[ -n "$TP_OUTPUT_STYLE" -a "$TP_OUTPUT_STYLE" != "classic" ] && {
	echo "$prgname: warning: only classic output style supported" >&2
}

[ -n "$TP_RA_SERVER" -a -z "$RA_SERVER" ] && RA_SERVER=$TP_RA_SERVER


[ -z "$cont" ] && exec traceroute $opts $host $length

while [ "$cont" -gt 0 ]
do
    cont=$(($cont - 1))
    traceroute $opts $host $length
done