Skip to content

Instantly share code, notes, and snippets.

@fledra
Created June 5, 2026 23:10
Show Gist options
  • Select an option

  • Save fledra/a55d58541a8b029a37d848c61b15678a to your computer and use it in GitHub Desktop.

Select an option

Save fledra/a55d58541a8b029a37d848c61b15678a to your computer and use it in GitHub Desktop.
ddclient - get ip from keenetic
#!/usr/bin/env sh
ROUTER="0.0.0.0"
USER="user"
PWD="password"
AUTH_URL="http://$ROUTER/auth"
RCI_URL="http://$ROUTER/rci"
COOKIE_JAR="/tmp/keenetic_cookies"
HEADERS=$(curl -si -c $COOKIE_JAR $AUTH_URL | tr -d "\r")
get_header() {
echo "$HEADERS" | grep -i "^$1:" | sed "s/^[^:]*: //i"
}
REALM=$(get_header "X-NDM-Realm")
CHALLENGE=$(get_header "X-NDM-Challenge")
MD5_SRC="$USER:$REALM:$PWD"
MD5_HASH=$(printf "%s" "$MD5_SRC" | md5sum | cut -d " " -f 1)
SHA_SRC="$CHALLENGE$MD5_HASH"
SHA_HASH=$(printf "%s" "$SHA_SRC" | sha256sum | cut -d " " -f 1)
PAYLOAD="{\"login\":\"$USER\",\"password\":\"$SHA_HASH\"}"
STATUS=$(curl -s -o /dev/null -b $COOKIE_JAR --json $PAYLOAD -w "%{http_code}" $AUTH_URL)
if [ $STATUS -ne 200 ]; then
echo "Failed to login. Status code: $STATUS"
exit 1
fi
PUBLIC_IP=$(curl -s -b "$COOKIE_JAR" "$RCI_URL/show/interface" | jq -r ".[] | select(.defaultgw==true and .address!=\"\") | .address")
rm -f $COOKIE_JAR
echo $PUBLIC_IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment