-
Notifications
You must be signed in to change notification settings - Fork 0
/
regip
executable file
·37 lines (31 loc) · 1.05 KB
/
regip
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
LOCK="/tmp/regip"
[[ -e "${LOCK}" ]] && exit 0
/usr/bin/touch "${LOCK}"
DYNDNS_SRV="https://sev.spacescience.ro"
APP_PATH="/dnsmasq/reg.php?"
SRV_URL="${DYNDNS_SRV}${APP_PATH}"
case "${1}" in
privateip)
PRIVATEIP="1"
shift
;;
thisip)
CUSTOM_IP="1"
shift
IP="${1}"
shift
;;
esac
if [[ -z "${CUSTOM_IP}" ]]; then
DEFAULT_IP=$(/sbin/ip route get $(/sbin/ip route show 0.0.0.0/0 | /bin/grep -oP 'via \K\S+') | /bin/grep -oP 'src \K\S+')
if [[ -n "${PRIVATEIP}" ]]; then
# we want only private addresses (we expect that the public ones even if dynamic are registered in dns)
IP="$(/bin/grep -P '/(^127\.)|(^192\.168\.)|(^10\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)/' <<< "${DEFAULT_IP}")" #'
else # use whatever is the default one (it has the default route)
IP="${DEFAULT_IP}"
fi
fi
[[ -z "${IP}" ]] && { echo "No ip selected"; exit 1; }
/usr/bin/timeout --kill-after=5 10 /usr/bin/curl -fslk --retry 3 --header "Forwarded: ${IP}" "${SRV_URL}$(/bin/hostname)"
/bin/rm -rf "${LOCK}"