-
Notifications
You must be signed in to change notification settings - Fork 2
/
findroute
executable file
·47 lines (41 loc) · 1018 Bytes
/
findroute
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
# (c) 2020 Leif Sawyer
# License: GPL 3.0 (see https://github.com/akhepcat/)
# Permanent home: https://github.com/akhepcat/Miscellaneous/
# Direct download: https://raw.githubusercontent.com/akhepcat/Miscellaneous/master/findroute
links=$(ip link show | grep '^[0-9]' | grep -vw lo: | wc -l)
if [ ${links:-999} -lt 2 ]
then
echo "all routes: $(ip route show default)"
exit 0
fi
IP=${1//[^0-9a-fA-F.:]/}
if [ "$1" != "${IP}" ]
then
echo "invalid IPv4 or IPv6 address"
exit 1
fi
if [ -z "${IP}" ]
then
echo "IPv4/IPv6 address to find route for?"
exit 1
fi
if [ "${IP##*:*}" != "${IP}" ]
then
six="-6"
tcidr=128
else
six=""
tcidr=32
fi
for cidr in $(seq $tcidr -1 0)
do
status=$(ip ${six} route show ${IP}/${cidr})
if [ -n "${status}" ]
then
status=${status// via/, routing via}
echo "${IP} contained in ${status}"
exit 0
fi
done
echo "unable to determine route. that's odd"