#!/bin/bash
TOKEN="your-oauth-token"# The API v2 OAuth token
ACCOUNT_ID="12345"# Replace with your account ID
ZONE_ID="yourdomain.com"# The zone ID is the name of the zone (or domain)
RECORD_ID="1234567"# Replace with the Record ID
IP=`curl --ipv4 -s http://icanhazip.com/`
curl -H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-X "PATCH" \
-i "https://api.dnsimple.com/v2/$ACCOUNT_ID/zones/$ZONE_ID/records/$RECORD_ID" \
-d "{\"content\":\"$IP\"}"
#!/usr/bin/env python# encoding: utf-8# Setup introductions:# Open Namecheap website, select a domain (e.g. abc.com) then go to Advanced DNS# (Accounts > Domain List > Advanced DNS)# Insert an "A + Dynamic DNS Record", with hostname (e.g. my) and type whatnever IP address.# Edit scripts for proper HOSTNAME (e.g. my.abc.com) and APIKEY (Dynamic DNS Password).# Run and have fun!import requests
import io, json
import certifi
from xml.etree import ElementTree
HOSTNAME="YOUR_HOSTNAME"# Namecheap hostname (including subdomain)
APIKEY="YOUR_DDNS_APIKEY"# Namecheap DDNS Token (Accounts > Domain List > Advanced DNS)defgetIP():
r = requests.get("https://ifconfig.co/json", verify=certifi.where()).json()
return r['ip']
defupdateRecord(ip):global HOSTNAME
global APIKEY
d = HOSTNAME.find('.')
host = HOSTNAME[:d]
domain = HOSTNAME[(d+1):]
# DO NOT change the url "dynamicdns.park-your-domain.com". It's vaild domain provide by namecheap.return requests.get("https://dynamicdns.park-your-domain.com/update?host=" + host + "&domain=" + domain + "&password=" + APIKEY + "&ip=" + ip, verify=certifi.where())
ip = getIP()
print("External IP: " + ip)
r = updateRecord(ip)
errCount = ElementTree.fromstring(r.content).find("ErrCount").text
if int(errCount) > 0:
print("API error\n" + r.content)
else:
print("Updete IP success!")
Demo title
T2
OK first time try HackMD
Some diagram
Images
Code
#!/usr/bin/env python # encoding: utf-8 # Setup introductions: # Open Namecheap website, select a domain (e.g. abc.com) then go to Advanced DNS # (Accounts > Domain List > Advanced DNS) # Insert an "A + Dynamic DNS Record", with hostname (e.g. my) and type whatnever IP address. # Edit scripts for proper HOSTNAME (e.g. my.abc.com) and APIKEY (Dynamic DNS Password). # Run and have fun! import requests import io, json import certifi from xml.etree import ElementTree HOSTNAME="YOUR_HOSTNAME" # Namecheap hostname (including subdomain) APIKEY="YOUR_DDNS_APIKEY" # Namecheap DDNS Token (Accounts > Domain List > Advanced DNS) def getIP(): r = requests.get("https://ifconfig.co/json", verify=certifi.where()).json() return r['ip'] def updateRecord(ip): global HOSTNAME global APIKEY d = HOSTNAME.find('.') host = HOSTNAME[:d] domain = HOSTNAME[(d+1):] # DO NOT change the url "dynamicdns.park-your-domain.com". It's vaild domain provide by namecheap. return requests.get("https://dynamicdns.park-your-domain.com/update?host=" + host + "&domain=" + domain + "&password=" + APIKEY + "&ip=" + ip, verify=certifi.where()) ip = getIP() print("External IP: " + ip) r = updateRecord(ip) errCount = ElementTree.fromstring(r.content).find("ErrCount").text if int(errCount) > 0: print("API error\n" + r.content) else: print("Updete IP success!")