Created
October 5, 2011 14:14
-
-
Save tonyskapunk/1264528 to your computer and use it in GitHub Desktop.
get_vpn_ip
This file contains 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 characters
[get_my_vpn_ip.sh] | |
#!/bin/bash | |
last_ip_file="/some/path/vpn/last_ip" | |
log_file="/some/path/vpn/vpn_ip.log" | |
if [ -e $last_ip_file ] | |
then | |
last_ip=$(cat /some/path/vpn/last_ip) | |
current_ip=$(/some/path/vpn/vpn_ip.sh) | |
if [ $? -eq 0 ] | |
then | |
if [ "$last_ip" != "$current_ip" ] | |
then | |
/some/path/vpn/vpn_ip.sh > /some/path/vpn/last_ip | |
now=$(date "+%s") | |
echo -ne "$now,$last_ip,$current_ip\n" > $log_file | |
exit 0 | |
fi | |
fi | |
exit 1 | |
fi | |
=== | |
[get_my_vpn_ip.sh] | |
#!/bin/bash | |
# Get IP of tunnel(tun0) if it is up. | |
is_tunnel_up() { | |
/sbin/ifconfig tun0 2>&1 >/dev/null | |
if [ $? -eq 0 ] | |
then | |
return 0 | |
fi | |
return 1 | |
} | |
get_vpn_ip() { | |
is_tunnel_up | |
if [ $? -ne 0 ] | |
then | |
return 1 | |
fi | |
vpn_ip=$(/sbin/ifconfig tun0|grep "inet add"|cut -d: -f2|cut -d" " -f1) | |
echo $vpn_ip | |
return 0 | |
} | |
main() { | |
vpn_ip=$(get_vpn_ip) | |
if [ $? -ne 0 ] | |
then | |
exit 1 | |
fi | |
echo $vpn_ip | |
exit 0 | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment