forked from acabal/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gateway
executable file
·35 lines (29 loc) · 831 Bytes
/
gateway
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
#!/bin/sh
usage(){
fmt <<EOF
DESCRIPTION
Display the gateway (typically the router) address of the current network.
USAGE
gateway
Print the gateway address to standard output.
gateway -o,--open
Open the gateway address in the default web browser.
EOF
exit
}
if [ $# -eq 1 ]; then if [ "$1" = "--help" -o "$1" = "-h" ]; then usage; fi fi
#End boilerplate
route | while read -r line; do
flagsColumn=$(echo "${line}" | tr -s ' '| cut -d ' ' -f 4)
if [ "${flagsColumn}" != "Flags" -a "${flagsColumn}" != "table" ]; then
flags=$(echo "${flagsColumn}" | egrep "G")
if [ "${flags}" != "" ]; then
address=$(echo "${line}" | tr -s ' '| cut -d ' ' -f 2)
if [ $# -eq 0 ]; then
echo "http://${address}"
elif [ "$1" = "-o" -o "$1" = "--open" ]; then
xdg-open "http://${address}"
fi
fi
fi
done