Commit 10dddcd6 authored by Yuanle Song's avatar Yuanle Song
Browse files

get IP from router. (user defined shell function)

parent d7d737de
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ it does not report errors.
  curl
  dig
  make
  python
  egrep

* start to use bugzilla to track feature requests and bugs.
  for open bugs see
+9 −0
Original line number Diff line number Diff line
@@ -12,3 +12,12 @@ PASSWORD=
HOSTNAME=
# using printf syntax, with %s being the new IP.
UPDATE_URL="https://$USERNAME:$PASSWORD@members.dyndns.org/nic/update?hostname=$HOSTNAME&myip=%s&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"

# get_ip_command function, if defined, should set MYIP variable to the IP
# address. It should return non 0 exit code on failure.

# This is the default definition, which fetch IP from ifconfig.me. It's
# recommended that you get IP from NIC, router or firewall.
# get_ip_command() {
# 	MYIP=`curl -s http://ifconfig.me`
# }
+10 −0
Original line number Diff line number Diff line
#!/bin/sh

# echo '4, "D8-5D-4C-58-2A-33", "49.79.141.87", 3, "255.255.255.255", 0, 0, "49.79.141.87", 0, 1, 0, "61.147.37.1 , 61.177.7.1", "0 day(s) 05:06:43", 1, 0, "0.0.0.0", "0.0.0.0", 0, 0, 0, ' |python -c 'i = raw_input(); print i.split(", ")[2][1:-1]'

# echo '4, "D8-5D-4C-58-2A-33", "", 3, "255.255.255.255", 0, 0, "49.79.141.87", 0, 1, 0, "61.147.37.1 , 61.177.7.1", "0 day(s) 05:06:43", 1, 0, "0.0.0.0", "0.0.0.0", 0, 0, 0, ' |python -c 'i = raw_input(); print i.split(", ")[2][1:-1]'

# TODO what will the array looks like when WAN port is not connected to
# internet.

curl -s http://sylecn:yxyxyy107@192.168.1.1/userRpm/StatusRpm.htm |grep -e 'var wanPara' -A 1 | tail -n +2 | python -c 'i = raw_input(); print i.split(", ")[2][1:-1]'
+19 −5
Original line number Diff line number Diff line
@@ -33,19 +33,33 @@ if [ -f "$CONFIG_FILE" ]; then
	. "$CONFIG_FILE"
else
	err "Error: No config file found at $CONFIG_FILE."
	echo "Error: No config file found at $CONFIG_FILE." > /dev/stderr
	exit $NO_CONF
fi

# set MYIP variable to my internet IP address.
# Returns true on success, false on failure.
get_myip() {
	if type get_ip_command > /dev/null 2>&1; then
		get_ip_command
		EXIT_CODE=$?
		if [ -z "$MYIP" ]; then
			err "Error: get_ip_command did not set MYIP variable."
			exit $GET_MYIP_FAILED
		fi
	else
		MYIP=`curl -s http://ifconfig.me`
	CURL_EXIT_CODE=$?
	if [ "$CURL_EXIT_CODE" -eq 0 ]; then
		EXIT_CODE=$?
	fi

	if [ "$EXIT_CODE" -ne 0 ]; then
		err "get_myip() failed. get_ip_command exit code is $EXIT_CODE."
		exit $GET_MYIP_FAILED
	fi

	if echo "$MYIP" | egrep -q -e '^[0-9]{1,3}(.[0-9]{1,3}){3}$'; then
		return 0
	else
		err "get_myip() failed. curl exit code is $CURL_EXIT_CODE."
		err "Error: IP address $MYIP is not well-formed."
		exit $GET_MYIP_FAILED
	fi
}