-
Notifications
You must be signed in to change notification settings - Fork 11
/
devof.sh
executable file
·57 lines (43 loc) · 956 Bytes
/
devof.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
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
# SPDX-FileCopyrightText: © 2020 Georg Sauthoff <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
function help
{
cat <<EOF
devof - list name(s) of network device(s) that use the given address (prefix)
call: devof [OPT...] ADDRESS|ADRESS/PREFIXLEN
Options:
-h, --help display this help and exit
EOF
}
addr=
function parse_args
{
local t
t=$(getopt -o h --long help -n addrof -- "$@")
if [ $? -ne 0 ]; then
echo 'Option parse error' >&2
exit 1
fi
eval set -- "$t"
while :; do
case "$1" in
-h|--help)
help
exit 0
shift
;;
--)
shift
break
;;
esac
done
if [ $# -lt 1 ]; then
echo 'device name missing' >&2
exit 1
fi
addr=$1
}
parse_args "$@"
ip -o addr show up to "$addr" | cut -d' ' -f2