4-19
Saturday
标签
梦涛笔记

ROS通过aliyun域名解析实现DDNS脚本

ROS 发布时间:2025-03-29 13:51:38
#aliyun Access Key
:local id "key"
:local secret "secret"

#domain
:local domain "your.domain.com"


#PPPoE-out
:local pppoe "pppoe-out1"

#阿里云DDNS服务器:

:local ipaddr [/ip address get [/ip address find interface=$pppoe] address]
:set ipaddr [:pick $ipaddr 0 ([len $ipaddr] -3)]
#:log info $ipaddr;
:local result [/tool fetch url="https://www.zhisg.com/route.php/ddns/ali/set\?id=$id&secret=$secret&domain=$domain&ip=$ipaddr" as-value output=user];
:log info $result;


#:global ddnspool "ipv6"
#:global ddnsinterface "bridge"
#:global ddnsinterface "6to4-henet"
#:global ddnsinterface "pppoe-out1"
#:global ddnsinterface "ether6"

# Define Global Variables
:global ddnsip
:global ddnslastip
:if ([ :typeof $ddnslastip ] = nil ) do={ :global ddnslastip "0" }


# Define Local Variables
:local int

# Loop thru interfaces and look for ones containing
# default gateways without routing-marks
:if ([ :typeof $ddnsinterface ] != "str" ) do={
  :foreach int in=[ /ipv6 address find global ] do={
    :local testip [ /ipv6 address get $int address ]
    :if ($testip in "fe80::/10" || $testip in "fc00::/7") do={
    } else={
      :global ddnsip $testip
    }
  }
} else={
  :if ([ :typeof $ddnspool ] != "str" ) do={
    # Grab the current Global IP address on that interface.
    :foreach int in=[ /ipv6 address find interface=$ddnsinterface global ] do={
      :local testip [ /ipv6 address get $int address ]
      :if ($testip in "fe80::/10" || $testip in "fc00::/7") do={
      } else={
        :global ddnsip $testip
      }
    }
  } else={
    # Grab the current Global IP address on that interface from spec ip pool.
    :global ddnsip [ /ipv6 address get [ /ipv6 address find interface=$ddnsinterface  from-pool=$ddnspool ] address ]
  }
}

# Did we get an IP address to compare?
:if ([ :typeof $ddnsip ] = nil ) do={
   :log info ("DynDNS: No ip address present on please check.")
} else={
  :log info ("DynDNS: check IPv6 UPDATE " . $ddnsip)
#  :if ($ddnsip != $ddnslastip) do={
:local result [/tool fetch url="https://www.zhisg.com/route.php/ddns/ali/set\?id=$id&secret=$secret&domain=$domain&ip=$ddnsip&type=AAAA" as-value output=user];
:log info $result;    
    :global ddnslastip $ddnsip
#  }
}


评论: