forked from NullHypothesis/backlogscans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
traceroute_host.sh
executable file
·47 lines (38 loc) · 1 KB
/
traceroute_host.sh
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
#!/bin/bash
#
# Copyright 2013, 2014 Philipp Winter <phw@nymity.ch>
source log.sh
if [ "$#" -lt 2 ]
then
echo
echo "Usage: $0 DST_ADDR DST_PORT [OUTPUT_DIR]"
echo
exit 1
fi
ip_addr="$1"
port="$2"
# Check if optional argument is given.
if [ ! -z "$3" ]
then
outdir="$3"
if [ ! -d $outdir ]
then
log "Creating directory \"${outdir}\"."
mkdir -p $outdir
fi
else
outdir="$(mktemp -d '/tmp/traceroutes-XXXXXX')"
fi
timestamp() {
local file="$1"
printf "Date in UTC: $(date -u --rfc-3339=ns)\n" >> $file
}
# Parse the input which is in the format of IP:port.
filebase="${outdir}/$(date -u +'%F.%T')_traceroute"
log "Running TCP traceroute to ${ip_addr}:${port} in the background."
timestamp "${filebase}_tcp"
timeout 10 traceroute -T -O ack -n -w 3 -p $port $ip_addr >> "${filebase}_tcp" 2>&1 &
log "Running ICMP traceroute to ${ip_addr} in the background."
timestamp "${filebase}_icmp"
timeout 10 traceroute -I -n -w 3 $ip_addr >> "${filebase}_icmp" 2>&1 &
log "Writing results to \"${filebase}_{tcp,icmp}\"."