-
-
Save alirezaomidi/9eeea3aa0a0a5a3404ea82f12741a475 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# This script connects the computer to a vpn server using openconnect without pain | |
prog_name=$(basename $0) | |
# CHANGE YOUR_VPN_SERVER_DOMAIN to the VPN server you know like example.com | |
domain=YOUR_VPN_SERVER_DOMAIN | |
function help { | |
echo "Usage: $prog_name [-c server] [-d]" | |
echo | |
echo "Options" | |
echo " -c, --connect <subdomain> Connect to the specified VPN server (subdomain.domain)" | |
echo " -d, --disconnect Disconnect the running VPN" | |
echo | |
} | |
function connect { | |
server=$1.$domain | |
echo "Connecting to $server..." | |
sudo openconnect -b $server < ~/Documents/vpnmakers.txt | |
} | |
function disconnect { | |
echo "Disconnecting..." | |
sudo pkill -SIGINT openconnect | |
# Remove default gateway route rule when there is already a PPTP connection | |
# Uncomment line below if your computer is connected to internet through a PPTP connection | |
ip r | grep ppp0 && ip r | grep default | head -n1 | xargs sudo ip r del | |
} | |
subcommand=$1 | |
case $subcommand in | |
"" | "-h" | "--help") | |
help | |
;; | |
"-c" | "--connect") | |
shift | |
connect $@ | |
;; | |
"-d" | "--disconnect") | |
disconnect | |
;; | |
*) | |
echo "Error: '$subcommand' is not a known command." >&2 | |
echo " Run '$prog_name --help' for a list of known commands." >&2 | |
exit 1 | |
;; | |
esac |
Agreed - thank you for the script. Can you please provide an example of vpnmakers.txt
?
I think vpnmakers.txt
might be something like this
serveraddress -u uername
just openconnect's arguments
Its a simple text file like this:
yes
VPN_USERNAME
VPN_PASSWORD
Use yes if your VPN server is insecure and openconnect
wants an agreement from you.
Its a simple text file like this:
yes VPN_USERNAME VPN_PASSWORD
Use yes if your VPN server is insecure and
openconnect
wants an agreement from you.
yeap. That's the right text file. 👍
Thank you for providing this.
Thank you for providing this.
YW.
Thank you for this. It works like a charm.
it's amazing,
thanks alireza jan :boos:
Thank you, you helped me realize that I was using the default kill
signal which is TERM which...according to openconnect manual, makes openconnect exit immediately without logging off or running vpnc-script and vpnc-script is responsible for restoring your route and dns which was not happening in my case making my internet connection run like in 90's on a telephone modem.
Thanks for the contribution, but when connecting it disables the internet connection.
Thank you.
Damet garm Ali jun <3
Hello,
Can you please post an example of maker.txt content ?
regards.