Skip to content

Instantly share code, notes, and snippets.

@jigangkim
Last active April 26, 2022 07:12
Show Gist options
  • Save jigangkim/41303e7a25394df04be6f5545c918c0c to your computer and use it in GitHub Desktop.
Save jigangkim/41303e7a25394df04be6f5545c918c0c to your computer and use it in GitHub Desktop.
vpnshift application commands /scripts
usage="usage: bash bash_vpnshift.sh -n <netns>"
quick_die() {
format="$1"; shift
>&2 printf "${format}\n" "$@"
exit 1
}
main() {
while getopts "hn:" opt; do
case "${opt}" in
h) quick_die "${usage}" ;;
n) netns="${OPTARG}" ;;
*) quick_die "unknown option: %s" "${opt}" ;;
esac
done
shift $(( OPTIND - 1 ))
if [[ -z "${netns}" ]]; then
quick_die "network namespace is required"
fi
sudo ip netns exec $netns sudo PULSE_SERVER=/run/user/$(id -u $USER)/pulse/native PULSE_COOKIE=/home/$USER/.config/pulse/cookie XDG_RUNTIME_DIR=/run/user/$(id -u $USER) -u $USER bash
}
main "$@"
usage="usage: bash firefox_vpnshift.sh -n <netns>"
quick_die() {
format="$1"; shift
>&2 printf "${format}\n" "$@"
exit 1
}
main() {
while getopts "hn:" opt; do
case "${opt}" in
h) quick_die "${usage}" ;;
n) netns="${OPTARG}" ;;
*) quick_die "unknown option: %s" "${opt}" ;;
esac
done
shift $(( OPTIND - 1 ))
if [[ -z "${netns}" ]]; then
quick_die "network namespace is required"
fi
sudo ip netns exec $netns sudo -u $USER firefox
}
main "$@"
usage="usage: bash spotify_vpnshift.sh -n <netns>"
quick_die() {
format="$1"; shift
>&2 printf "${format}\n" "$@"
exit 1
}
main() {
while getopts "hn:" opt; do
case "${opt}" in
h) quick_die "${usage}" ;;
n) netns="${OPTARG}" ;;
*) quick_die "unknown option: %s" "${opt}" ;;
esac
done
shift $(( OPTIND - 1 ))
if [[ -z "${netns}" ]]; then
quick_die "network namespace is required"
fi
sudo ip netns exec $netns sudo -u $USER spotify
}
main "$@"

Commands

Apply VPN to a single process().

$ sudo bash ./vpnshift -c <OVPN FILE> -i <INTERFACE> -u <USER> [<COMMAND> [<ARG>...]]

Establish a VPN network namespace with a dummy command.

$ sudo bash ./vpnshift -c <OVPN FILE> -i <INTERFACE> -u <USER> ping google.com

..and attach multiple processes to it.

$ sudo ip netns exec <NAMESPACE> sudo -u <USER> [<COMMAND> [<ARG>...]]
sudo bash ./vpnshift -c ./pitbull.ovpn -i enp3s0 -u $USER -v 0 ping google.com -i 60
usage="usage: bash vpnshift_proton.sh -c <country> -n <number>"
quick_die() {
format="$1"; shift
>&2 printf "${format}\n" "$@"
exit 1
}
main() {
while getopts "hc:n:" opt; do
case "${opt}" in
h) quick_die "${usage}" ;;
c) country="${OPTARG}" ;;
n) number="${OPTARG}" ;;
esac
done
shift $(( OPTIND - 1 ))
if [[ -z "${country}" ]]; then
quick_die "country code is required (us, nl, jp)"
exit 1
fi
if [[ -z "${number}" ]]; then
quick_die "server number is required (01, 02, ...)"
exit 1
fi
secret="U2FsdGVkX19xiwF3QshXbtr0AOJb2fLOin/QeibsZIYX0QiF8Pzwzds7EKTr+sciweLX10yi6zWpszaJGyIYLQ=="
echo -n "ProtonVPN(free) password: "
read -s password
echo
vpn_user="lprN1U61hTBb8d1t+f2" # "lprN1U61hTBb8d1t" or "lprN1U61hTBb8d1t+f1" or "lprN1U61hTBb8d1t+f2"
vpn_password=`echo $secret | openssl aes-256-cbc -pbkdf2 -d -a -pass pass:$password`
auth="${vpn_user}\n${vpn_password}"
sudo bash ./vpnshift -c ./proton_ovpns/${country}free${number}.ovpn -i enp3s0 -u $USER -a "$auth" -v 7 ping google.com -i 60
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment