Advertisement
commandlinekid

Proton VPN Command Line Script (start/stop) script for Linux

Jun 13th, 2019
1,497
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.82 KB | None | 0 0
  1. HERE IS A SCRIPT to launch proton vpn from the linux command line. Checks to see if running when you stop it (to make sure it's not still running) and spits out the IP address after pausing 5 seconds.
  2.  
  3. Is this sloppy? Yes.
  4. Does it work? Yes.
  5. Is it foolproof? No. So make it better. But it works well for now for what I need.
  6.  
  7. Below: Two scripts. The main script and the IP Address checker. If you run this on a different version of Linux than me you might need to tweak the tool names.
  8.  
  9. SCRIPT 1
  10. #!/bin/sh
  11.  
  12. # config files are in /etc/openvpn and /etc/openvpn/client
  13. # yes I am using one of the "free servers" from Proton VPN. You could make this script do a round-robin if you wanted I think, why not.
  14.  
  15. SEARCH1="${1}"
  16. PRINTSERVICESTATUS=0
  17. SERVICENAME="[email protected]"
  18.  
  19. if [ -z "$SEARCH1" ]
  20. then
  21. echo "You didn't enter anything. Try again."
  22. else
  23.        printf "\n"
  24.        if [ "$SEARCH1" == "start" ]; then
  25.                sudo systemctl start  $SERVICENAME
  26.        PRINTSERVICESTATUS=1
  27.        elif [ "$SEARCH1" == "stop" ]; then
  28.                sudo systemctl stop $SERVICENAME
  29.  
  30.        proctocheck="openvpn"
  31.        procstillrunning=$(ps -ef | grep "$proctocheck" | grep -v "grep" | wc -l)
  32.        PRINTSERVICESTATUS=1
  33.        if (( "$procstillrunning" > 0 )); then
  34.        printf "\n\n\n\n"
  35.        echo "**************NOTE: ""$proctocheck"" STILL RUNNING ""$procstillrunning"" TIMES. GO KILL IT."
  36.        printf "\n\n\n\n"
  37.        echo "Procs still running...."
  38.        ps -ef | grep "$proctocheck" | grep -v "grep"
  39.        fi
  40.        elif [ "$SEARCH1" == "status" ]; then
  41.        PRINTSERVICESTATUS=1
  42.        else
  43.                printf "\n\n"
  44.        echo "You did not send any option we recognize. Exiting."
  45.        fi
  46.  
  47.         if (( "$PRINTSERVICESTATUS" > 0)); then
  48.          # works too myipaddressis=$(curl ifconfig.me --silent)
  49.        sudo systemctl is-active $SERVICENAME  >/dev/null 2>&1 && echo "$SERVICENAME IS ON" && printf "\n" || echo "$SERVICENAME IS OFF" && printf "\n";
  50.        sudo systemctl is-active $SERVICENAME  >/dev/null 2>&1 && servicestatus=1 || servicestatus=0;
  51.        # fine for testing echo $servicestatus
  52.        if [ "$servicestatus" -eq 1 ];
  53.                then
  54.                secondspause=5;
  55.        echo "Pausing $secondspause seconds to check for current IP Address:";
  56.          sleep $secondspause;
  57.                fi
  58.        # IP Address script checker so we can use that script for other stuff too and improve on it. aka.... code sharing
  59.        sh ./ipaddress
  60.  
  61.         fi
  62.  
  63. fi
  64.  
  65. /SCRIPT 1
  66.  
  67. SCRIPT 2
  68. #!/bin/sh
  69.  
  70. # Updated 06/14/2019 07:20 ET
  71.  
  72.        myip=$(dig +short myip.opendns.com @resolver1.opendns.com)
  73.        myip_reversedomainlookup=$(host $myip)
  74.        ReverseDomainLookup="$(dig +noall +answer -x $myip)"
  75.        if [[ -z "$ReverseDomainLookup" ]];
  76.        then
  77.        ReverseDomainLookup="nothing";
  78.        ADDITIONALINFOTOPRINT="ISP: UNKNOWN"
  79.        else
  80.                if [[ $myip_reversedomainlookup =~ "rr.com" ]]
  81.                then
  82.                ADDITIONALINFOTOPRINT="ISP: TIME WARNER"
  83.                elif [[ $myip_reversedomainlookup =~ "NEXTONEPLACEHOLDER" ]]
  84.                then
  85.                ADDITIONALINFOTOPRINT="PLACEHOLDER"
  86.                else
  87.                # There is something in reverse domain lookup so pull out the root domain using regex....
  88.                re="(.*)(\.)(([a-zA-Z0-9]+)(\.)([a-zA-Z0-9]+))"
  89.                if [[ $myip_reversedomainlookup =~ $re ]]; then ADDITIONALINFOTOPRINT="ISP: "${BASH_REMATCH[3]}; fi
  90.                fi
  91.        fi
  92.       printf "My IP Address is\n$myip\nReverse:\n$myip_reversedomainlookup\n"
  93.  
  94. if [[ -n "$ADDITIONALINFOTOPRINT" ]];
  95.        then
  96.        printf "$ADDITIONALINFOTOPRINT"
  97.        printf "\n"
  98.        fi
  99.  
  100.  
  101.  
  102.  
  103. /SCRIPT 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement