Skip to content

Commit

Permalink
Now 'ucsf vpn routing --full' reports on some 'whois' information too
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed May 14, 2024
1 parent 4035fee commit 1e0a1d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ ucsf-vpn
* Add `ucsf vpn routing`, which shows the current IP routing table.
It also reports on the default non-VPN network interface on the
machine. By specifying `--full`, IP numbers are annotated with
hostnames, if available.
hostnames and `whois` information, if available.

* Now `ucsf vpn start` and `ucsf vpn stop` wait for the updating of
the IP routing table (`ip route show`) to finish before returning.
Expand Down
35 changes: 25 additions & 10 deletions bin/ucsf-vpn
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
### * UCSF Managing Your Passwords:
### - https://it.ucsf.edu/services/managing-your-passwords
###
### Version: 5.7.0-9016
### Version: 5.7.0-9017
### Copyright: Henrik Bengtsson (2016-2024)
### License: GPL (>= 2.1) [https://www.gnu.org/licenses/gpl.html]
### Source: https://github.com/HenrikBengtsson/ucsf-vpn
Expand Down Expand Up @@ -330,33 +330,48 @@ function connection_details() {
}

function routing_details() {
local -a ip_route
local ip domain
local -a ip_route info
local ip
local -i kk
local use_dig=true
local use_whois=true

mdebug "routing_details()"

if $full; then
command -v dig &> /dev/null || use_dig=false
mdebug "Command 'dig' available: ${use_dig}"
if ! $use_dig; then
mwarn "Cannot lock up hostname information for IP addresses (--full), because 'dig' is missing. Install the 'dig' tool to fix this"

command -v whois &> /dev/null || use_dig=false
mdebug "Command 'whois' available: ${use_whois}"

if ! $use_dig && ! $use_whois; then
mwarn "Cannot lock up hostname information for IP addresses (--full). Install 'dig' or 'whois' to fix this"
fi
else
use_dig=false
use_whois=false
fi

echo "Default non-VPN network interface: $(ip_route_novpn_interface)"
mapfile -t ip_route < <(ip route show)
echo "IP routing table (${#ip_route[@]} entries):"
for kk in "${!ip_route[@]}"; do
row="${ip_route[${kk}]}"
if $use_dig && grep -q -E "^([[:digit:].]+).*" <<< "${row}"; then
ip=$(sed -E 's/^([[:digit:].]+).*/\1/' <<< "${row}")
domain=$(dig -x "${ip}" +short | grep -vF "/" | sed -E 's/[.]$//' | tr $'\n' ',' | sed -E 's/,$//')
if [[ -n ${domain} ]]; then
row="${row}[${domain}]"
if $use_dig || $use_whois; then
if grep -q -E "^([[:digit:].]+).*" <<< "${row}"; then
ip=$(sed -E 's/^([[:digit:].]+).*/\1/' <<< "${row}")
mapfile -t info < <(
if $use_dig; then
dig -x "${ip}" +short | grep -vF "/" | sed -E 's/[.]$//'
fi
if $use_whois; then
whois "${ip}" | grep -i -E "^(country|netname|orgname):" | sed -E 's/^([[:alpha:]]+):[[:space:]]+/\1=/I' | sort | uniq # | sed -i -E 's/^(netname|orgname):[[:space:]]+//I'
fi
)
if [[ ${#info[@]} -gt 0 ]]; then
row="${row}[$(printf "%s; " "${info[@]}" | sed -E 's/; $//')]"
fi
fi
fi
echo "${row}"
Expand Down

0 comments on commit 1e0a1d4

Please sign in to comment.