Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.
- Is this sloppy? Yes.
- Does it work? Yes.
- Is it foolproof? No. So make it better. But it works well for now for what I need.
- 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.
- SCRIPT 1
- #!/bin/sh
- # config files are in /etc/openvpn and /etc/openvpn/client
- # 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.
- SEARCH1="${1}"
- PRINTSERVICESTATUS=0
- SERVICENAME="[email protected]"
- if [ -z "$SEARCH1" ]
- then
- echo "You didn't enter anything. Try again."
- else
- printf "\n"
- if [ "$SEARCH1" == "start" ]; then
- sudo systemctl start $SERVICENAME
- PRINTSERVICESTATUS=1
- elif [ "$SEARCH1" == "stop" ]; then
- sudo systemctl stop $SERVICENAME
- proctocheck="openvpn"
- procstillrunning=$(ps -ef | grep "$proctocheck" | grep -v "grep" | wc -l)
- PRINTSERVICESTATUS=1
- if (( "$procstillrunning" > 0 )); then
- printf "\n\n\n\n"
- echo "**************NOTE: ""$proctocheck"" STILL RUNNING ""$procstillrunning"" TIMES. GO KILL IT."
- printf "\n\n\n\n"
- echo "Procs still running...."
- ps -ef | grep "$proctocheck" | grep -v "grep"
- fi
- elif [ "$SEARCH1" == "status" ]; then
- PRINTSERVICESTATUS=1
- else
- printf "\n\n"
- echo "You did not send any option we recognize. Exiting."
- fi
- if (( "$PRINTSERVICESTATUS" > 0)); then
- # works too myipaddressis=$(curl ifconfig.me --silent)
- sudo systemctl is-active $SERVICENAME >/dev/null 2>&1 && echo "$SERVICENAME IS ON" && printf "\n" || echo "$SERVICENAME IS OFF" && printf "\n";
- sudo systemctl is-active $SERVICENAME >/dev/null 2>&1 && servicestatus=1 || servicestatus=0;
- # fine for testing echo $servicestatus
- if [ "$servicestatus" -eq 1 ];
- then
- secondspause=5;
- echo "Pausing $secondspause seconds to check for current IP Address:";
- sleep $secondspause;
- fi
- # IP Address script checker so we can use that script for other stuff too and improve on it. aka.... code sharing
- sh ./ipaddress
- fi
- fi
- /SCRIPT 1
- SCRIPT 2
- #!/bin/sh
- # Updated 06/14/2019 07:20 ET
- myip=$(dig +short myip.opendns.com @resolver1.opendns.com)
- myip_reversedomainlookup=$(host $myip)
- ReverseDomainLookup="$(dig +noall +answer -x $myip)"
- if [[ -z "$ReverseDomainLookup" ]];
- then
- ReverseDomainLookup="nothing";
- ADDITIONALINFOTOPRINT="ISP: UNKNOWN"
- else
- if [[ $myip_reversedomainlookup =~ "rr.com" ]]
- then
- ADDITIONALINFOTOPRINT="ISP: TIME WARNER"
- elif [[ $myip_reversedomainlookup =~ "NEXTONEPLACEHOLDER" ]]
- then
- ADDITIONALINFOTOPRINT="PLACEHOLDER"
- else
- # There is something in reverse domain lookup so pull out the root domain using regex....
- re="(.*)(\.)(([a-zA-Z0-9]+)(\.)([a-zA-Z0-9]+))"
- if [[ $myip_reversedomainlookup =~ $re ]]; then ADDITIONALINFOTOPRINT="ISP: "${BASH_REMATCH[3]}; fi
- fi
- fi
- printf "My IP Address is\n$myip\nReverse:\n$myip_reversedomainlookup\n"
- if [[ -n "$ADDITIONALINFOTOPRINT" ]];
- then
- printf "$ADDITIONALINFOTOPRINT"
- printf "\n"
- fi
- /SCRIPT 2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement