admin';?>

首页 / 工作日志

namesilo.com ddns 脚本

By admin  •  2020-10-08 13:55:16  •  312次点击
永久外链: https://i.otherhill.com/static/d6dd69bb092a11eba02b809b202ce664.html

国内服务商:
curl -s https://api.myip.la


国外服务商:
curl -s -4 https://ifconfig.co
curl -s -6 https://ifconfig.co
curl -s -4 icanhazip.com
curl -s -6 ident.me

无需第三方网站, 获得本机公网IPV4, IPV6
dig -4 +short myip.opendns.com @resolver2.opendns.com
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com

dig -6 +short myip.opendns.com aaaa @resolver1.ipv6-sandbox.opendns.com

curl   -4 http://myip.dnsomatic.com/
curl  -4 http://whatismyip.akamai.com/
 

#!/bin/bash

#http://blog.pztop.com/2016/04/25/Namesilo-with-DDNS/
DOMAIN="otherhill.com"
APIKEY="xxxxxxx"
 
HOST="ddns"
CURL=`which curl`
 

NAMESILO_TMP_DIRECTORY=/tmp/.namesilo/
mkdir -p $NAMESILO_TMP_DIRECTORY

##Saved history pubic IP from last check
IP_FILE=$NAMESILO_TMP_DIRECTORY"MyPubIP"
RESPONSE=$NAMESILO_TMP_DIRECTORY"namesilo_response.xml"
 
##Get the current public IP 
#http://whatismyip.akamai.com/
#http://icanhazip.com/  can get ipv6
#http://myip.dnsomatic.com/
#wget -q -O - checkip.dyndns.com | grep -Po "[\d\.]+"
 
#CUR_IP=$($CURL -s https://whatismyip.akamai.com/)
CUR_IP=$(dig -4  TXT +short o-o.myaddr.l.google.com @ns1.google.com| sed -e "s/^['\"]//" -e "s/['\"]$//")

#去除前导空格
CUR_IP="${CUR_IP#"${CUR_IP%%[![:space:]]*}"}"
#去除尾部空格
CUR_IP="${CUR_IP%"${CUR_IP##*[![:space:]]}"}"


if [ $? -ne 0 ] || [ x$CUR_IP == 'x' ]; then CUR_IP=$($CURL -s http://myip.dnsomatic.com/) fi ##Exit if curl failed if [ $? -ne 0 ]; then echo "$CURL -s api.online-service.vip/ip/me faild!I can't get your public ip" fi echo "current public IPv4 is: "$CUR_IP if [[ $CUR_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then echo $CUR_IP " is good" else echo $CUR_IP " is invalid!!" exit fi ##Check file for previous IP address if [ -f $IP_FILE ]; then #取首行ipv4地址 KNOWN_IP=$(head $IP_FILE -n 1|tail -n 1) else KNOWN_IP= fi echo "old public IPv4 is: "$KNOWN_IP #86400 one day array_hosts=( "*" "yoursubdomain0" "yoursubdomain1" "yoursubdomain2" ) array_v6hosts=() if [ "$CUR_IP" != "$KNOWN_IP" ]; then echo "$CUR_IP != $KNOWN_IP" else echo "$CUR_IP == $KNOWN_IP" fi ##See if the IP has changed if [ "$CUR_IP" != "$KNOWN_IP" ]; then CUR_IP6=$($CURL -s http://ip6only.me/api/ |awk -F, '{print $2}') if [ $? -ne 0 ]; then CUR_IP6=$($CURL -s http://v6.ipv6-test.com/api/myip.php) fi echo "current public IPv6 is: "$CUR_IP6 ##Update DNS record in Namesilo: $CURL -s "https://www.namesilo.com/api/dnsListRecords?version=1&type=xml&key=$APIKEY&domain=$DOMAIN" > $DOMAIN.xml RECORD_ID=`xmllint --xpath "//namesilo/reply/resource_record/record_id[../host/text() = '$HOST.$DOMAIN' ]" $DOMAIN.xml | grep -oP '(?<=<record_id>).*?(?=</record_id>)'` $CURL -s "https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=$APIKEY&domain=$DOMAIN&rrid=$RECORD_ID&rrhost=$HOST&rrvalue=$CUR_IP&rrttl=3600" > $RESPONSE RESPONSE_CODE=`xmllint --xpath "//namesilo/reply/code/text()" $RESPONSE` case $RESPONSE_CODE in 300) echo $CUR_IP > $IP_FILE echo $CUR_IP6 >> $IP_FILE for i in "${array_hosts[@]}" do HOST=$i RECORD_ID=`xmllint --xpath "//namesilo/reply/resource_record/record_id[../host/text() = '$HOST.$DOMAIN' ]" $DOMAIN.xml | grep -oP '(?<=<record_id>).*?(?=</record_id>)'` $CURL -s "https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=$APIKEY&domain=$DOMAIN&rrid=$RECORD_ID&rrhost=$HOST&rrvalue=$CUR_IP&rrttl=3600" > $RESPONSE echo "$HOST".$DOMAIN"'s Ip have been changed to "$CUR_IP" successfully!" done for i in "${array_v6hosts[@]}" do HOST=$i RECORD_ID=`xmllint --xpath "//namesilo/reply/resource_record/record_id[../host/text() = '$HOST.$DOMAIN' ]" $DOMAIN.xml | grep -oP '(?<=<record_id>).*?(?=</record_id>)'` $CURL -s "https://www.namesilo.com/api/dnsUpdateRecord?version=1&type=xml&key=$APIKEY&domain=$DOMAIN&rrid=$RECORD_ID&rrhost=$HOST&rrvalue=$CUR_IP6&rrttl=3600" > $RESPONSE echo "$HOST".$DOMAIN"'s Ip6 have been changed to "$CUR_IP6" successfully!" done logger -t IP.Check -- Update success. Now $HOST.$DOMAIN IP address is $CUR_IP;; 280) logger -t IP.Check -- Duplicate record exist. No update necessary;; *) logger -t IP.Check -- DDNS update failed!;; esac #echo $RECORD_ID logger -t IP.Check -- Public IP changed to $CUR_IP and $CUR_IP6 else logger -t IP.Check -- NO IP change fi

#sudo tail /var/log/messages -c 50000|grep IP #echo > /tmp/.namesilo/MyPubIP #dig yourdomain.com @ns1.dnsowl.com #dig yourdomain.com AAAA @ns1.dnsowl.com #https://crontab.guru/ #crontab -e #*/30 * * * * /home/tashan/namesilo/update_ddns.sh exit 0

see more:
1. 无需网络,获取光猫公网IP:  https://i.otherhill.com/index.php/topic/show/538





0 回复 | 直到2022-06-28 19:20添加回复

回复

最近更新

私信给我
生成图片 生成二维码 生成密码
清空