1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-02-13 02:51:50 +00:00

Get ip via VPS script

This commit is contained in:
Ycarus (Yannick Chabanois) 2020-04-22 19:09:50 +02:00
parent 8880acd39e
commit 7ed99f1e38

View file

@ -1,10 +1,35 @@
#!/bin/sh
check_ipv4_website="$(uci -q get openmptcprouter.settings.check_ipv4_website)"
[ -z "$check_ipv4_website" ] && check_ipv4_website="http://ip.openmptcprouter.com"
checkip=$(echo $check_ipv4_website | sed -e 's/https:\/\///' -e 's/http:\/\///' | xargs dig +short A | tr -d "\n")
ipset add ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
ip="$(curl -s -4 -m 2 --interface $1 $check_ipv4_website)"
ipset del ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
if expr "$ip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
echo $ip
fi
. /lib/functions.sh
intf=$1
get_ip_from_server() {
serverip=$(uci -q get openmptcprouter.$1.ip)
serverport=$(uci -q get openmptcprouter.$1.port)
getip="$(curl -s -k -4 -m 2 --interface $intf https://$serverip:$serverport/clienthost)"
[ -n "$getip" ] && getip=$(echo $getip | jsonfilter -e '@.client_host')
if expr "$getip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
ip=$getip
break
fi
}
get_ip_from_website() {
check_ipv4_website="$(uci -q get openmptcprouter.settings.check_ipv4_website)"
[ -z "$check_ipv4_website" ] && check_ipv4_website="http://ip.openmptcprouter.com"
checkip=$(echo $check_ipv4_website | sed -e 's/https:\/\///' -e 's/http:\/\///' | xargs dig +short A | tr -d "\n")
ipset add ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
getip="$(curl -s -4 -m 2 --interface $intf $check_ipv4_website)"
ipset del ss_rules_dst_bypass_all $checkip > /dev/null 2>&1
if expr "$getip" : '[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
ip=$getip
break
fi
}
[ -z "$intf" ] && return
ip=""
config_load openmptcprouter
config_foreach get_ip_from_server server
[ -z "$ip" ] && get_ip_from_website
echo $ip