Created
June 5, 2026 23:10
-
-
Save fledra/a55d58541a8b029a37d848c61b15678a to your computer and use it in GitHub Desktop.
ddclient - get ip from keenetic
This file contains hidden or 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
| #!/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