Last active
April 9, 2017 22:57
-
-
Save gsanders5/33f22f29602387b0ff1b5a98f5338ef2 to your computer and use it in GitHub Desktop.
Revisions
-
gsanders5 revised this gist
Apr 9, 2017 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ function valid_ip() # Set the origional IP address, without the proxy nmcli con down "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" # Double check the proxy is offline origip="$(curl -s http://ipv4.icanhazip.com/)" # If run directly, execute some tests. if valid_ip $origip; then @@ -41,13 +41,13 @@ nmcli con up "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" while true do if [ "$(curl -s http://ipv4.icanhazip.com/)" == "$origip" ]; then echo "Error, IP has changed... reconnecting to the proxy" nmcli con down "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" sleep 1 nmcli con up "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" # else # echo "Still behind a proxy" fi sleep 1800 done -
gsanders5 created this gist
Apr 9, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ #!/bin/bash # Test an IP address for validity: # Usage: # valid_ip IP_ADDRESS # if [[ $? -eq 0 ]]; then echo good; else echo bad; fi # OR # if valid_ip IP_ADDRESS; then echo good; else echo bad; fi # function valid_ip() { local ip=$1 local stat=1 if [[ $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then OIFS=$IFS IFS='.' ip=($ip) IFS=$OIFS [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 \ && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] stat=$? fi return $stat } # Set the origional IP address, without the proxy nmcli con down "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" # Double check the proxy is offline origip="$(curl -s http://rvnxipv4.rvnx.org/)" # If run directly, execute some tests. if valid_ip $origip; then echo "Valid IP" else echo "Invalid IP" exit fi # Connect the the proxy without error on first run nmcli con up "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" while true do if [ "$(curl -s http://rvnxipv4.rvnx.org/)" == "$origip" ]; then echo "Error, IP has changed... reconnecting to the proxy" nmcli con down "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" sleep 1 nmcli con up "79cb5c38-f63e-4abe-9936-7cd1bcee4fb3" # else # echo "Still behind a proxy" fi sleep 120 done