Skip to content

Instantly share code, notes, and snippets.

@ahmpro
Last active September 12, 2021 12:31
Show Gist options
  • Save ahmpro/f1fceddf1ac62d60980d to your computer and use it in GitHub Desktop.
Save ahmpro/f1fceddf1ac62d60980d to your computer and use it in GitHub Desktop.
Yandex dDNS handmade for OpenWrt
#!/bin/bash
# Author: ahmpro and community
# gist url: https://gist.github.com/ahmpro/f1fceddf1ac62d60980d
# Yandex dDNS(handmade Dynamic DNS) for OpenWrt
# Tested on OpenWrt Chaos Calmer r46612, LuCI (git-15.216.69575-bb7ea3e)
# You should install curl (don't forget update packages list)
# Get __TOKEN__: https://pddimp.yandex.ru/api2/admin/get_token
# Get __RECORD_ID__:
# curl -H 'PddToken: __TOKEN__' 'https://pddimp.yandex.ru/api2/admin/dns/list?domain=domain.com'
# and find domain that you need in result, may use http://pro.jsonlint.com/ for pretty json :)
# for more detail about Yandex API see https://tech.yandex.ru/pdd/doc/concepts/api-dns-docpage/
__TOKEN__=1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
__DOMAIN__=example.com
__SUBDOMAIN__=home
__RECORD_ID__=123456
__TTL__=14400
__IP__=$__IP # inner var from openwrt
# as you know this script parsed inside send_update() of /usr/lib/ddns/dynamic_dns_functions.sh
# if you don't know that see http://wiki.openwrt.org/doc/uci/ddns
write_log 7 "curl -H 'PddToken: \$__TOKEN__' -d 'domain=$__DOMAIN__&subdomain=$__SUBDOMAIN__&record_id=$__RECORD_ID__&ttl=$__TTL__&content=$__IP__' 'https://pddimp.yandex.ru/api2/admin/dns/edit' -vk"
write_log 7 `curl -H "PddToken: $__TOKEN__" -d "domain=$__DOMAIN__&subdomain=$__SUBDOMAIN__&record_id=$__RECORD_ID__&ttl=$__TTL__&content=$__IP__" "https://pddimp.yandex.ru/api2/admin/dns/edit" -vk`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment