-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathavoid-vpn
39 lines (35 loc) · 1.41 KB
/
avoid-vpn
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
#! /bin/bash
#----------------------------------------------------------------------
# Description: avoid VPN for certain either predefined or given hosts
# Author: Artem S. Tashkinov
# Created at: Mon Jan 1 22:09:05 2018
# Thu Jan 31 15:40:07 2019 exclude tun when looking for a defgw
# 2019-08-27 14:15:16 - no idea what it was
# Wed 16 Oct 2019 08:58:46 PM - beautify IP using printf
# 2022-07-18 16:37:59 - print debug only in the interactive console
#
# Computer: localhost.localdomain
# System: Linux 4.14.10-ic64 on x86_64
#
# Copyright (c) 2018 Artem S. Tashkinov All rights reserved.
#----------------------------------------------------------------------
eko()
{
test "$TERM" = "linux" -o "$TERM" = "xterm-256color" && echo "$@"
}
default=( "irc.freenode.net" "en.wikipedia.org" "distrowatch.com" "wiki.debian.org" "irc.gnome.org" )
(( $# == 0 )) && set -- "${default[@]}" # Set arguments to $default if no command line arguments are given
defgw=`ip r | grep -v tun | awk '/default via/{print $3}'`
test -z "$defgw" && eko "Default gateway is not defined" && exit 1
eko "Default gateway is $defgw"
for i in "$@"; do
eko "Routing $i ... "
for IP in `host "$i" | awk '/has address/{print $4}'`; do
printf " %-14s : " "$IP"
if [ -z "`ip r | grep -w "$IP"`" ]; then
ip r a "$IP/32" via "$defgw" && eko "OK" || eko "failed"
else
eko "already routed"
fi
done
done