Finished them now. I have them setup so the DDNS one is called every 5 minutes by scheduler, and when it detects the wan IP needs updating to no-ip, it will do that, and THEN call the seperate HE-NET script. You can comment out the logs as needed. I found them useful when I was trying to make the scripts.
Name: DDNS
Site1 Site2 etc is handy for deploying the script to multiple sites. The script sets the hostname depending on what the RB Identity is. I use it for setting different DNS hosts for VPN.
Code: Select all
# Set needed variables
:global username "USERNAME"
:global password "PASSWORD"
:global hostname "nohostset"
:global wanInt "WAN INTERFACE NAME"
:global systemname [/system identity get name]
:if ($systemname = "Site1" ) do= {
:set hostname "site1.abc.com"
}
:if ($systemname = "Site2" ) do= {
:set hostname "site2.abc.com"
}
:if ($systemname = "Site3" ) do= {
:set hostname "yourdomain3.no-ip.org"
}
:global noipForce
:global previousIP
# print some debug info
#:log info ("DDNS: username = $username")
#:log info ("DDNS: password = $password")
:log info ("DDNS: hostname = $hostname")
:log info ("DDNS: previousIP = $previousIP")
# Grab the current IP address on that interface.
:global ddnsip [/ip address get [/ip address find interface="$wanInt"] address]
:global currentIP [:pick $ddnsip 0 [:find $ddnsip "/"]]
#:log info ("DDNS: ddnsip = $ddnsip")
:log info ("DDNS: currentIP = $currentIP")
# Remove the # on next line to force an update every single time - useful for debugging, but you could end up getting blacklisted by No-IP!
#:set noipForce true
# Determine if no-ip update is needed
# more no-ip updater request details available at http://www.no-ip.com/integrate/request/
:if (($currentIP != $previousIP) || ($noipForce = true)) do={
:set noipForce false
:set previousIP $currentIP
:log info ("DDNS: No-IP update needed")
:log info ("DDNS: Start of Fetch")
global tmp [/tool fetch mode=http port=80 address=dynupdate.no-ip.com host=dynupdate.no-ip.com src-path="/nic/update?hostname=$hostname&myip=$currentIP" user=$username password=$password dst-path="/noip.txt"]
:log info ("DDNS: End of Fetch")
:global result [/file get noip.txt contents]
:log info ("DDNS: No-IP Update Result: $result")
:put ("No-IP Update Result: $result")
# Update HE.net Tunnel
:execute script=HE-NET
} else={
:log info ("DDNS: No No-IP update needed")
}
Script name: HE-NET
Code: Select all
:global HEusername "HE USER ID (LONG MD5 HASH VERSION)"
:global HEpassword "PASSWORD IN MD5"
:global HEtid "TUNNEL UID"
:global HEint "6TO4 INTERFACE NAME"
:global HEwan "WAN INTERFACE NAME"
:log info ("HE-UPD: Finding bt-wan IP")
:global HEcurrentIP [/ip address get [/ip address find interface="$HEwan"] address]
:log info ("HE-UPD: $HEcurrentIP")
:set HEcurrentIP [:pick $HEcurrentIP 0 [:find $HEcurrentIP "/"]]
:log info ("HE-UPD: $HEcurrentIP")
:log info ("HE-UPD: ---6to4 update being attempted interface---")
/interface 6to4 set "$HEint" disabled=yes
:log info ("HE-UPD: sit1 disabled")
/interface 6to4 set "$HEint" disabled=no local-address=$HEcurrentIP
:log info ("HE-UPD: 6to4 new v4addr set and re-enabled")
:log info ("HE-UPD: Start Fetch")
/tool fetch mode=http port=80 address=ipv4.tunnelbroker.net host=ipv4.tunnelbroker.net src-path="/ipv4_end.php\?ipv4b=$HEcurrentIP&pass=$HEpassword&user_id=$HEusername&tunnel_id=$HEtid" dst-path="henet.txt"
:delay 1
:log info ("HE-UPD: Fetch done")
:global 6to4OUT [/file get henet.txt contents]
:log info "HE-UPD: 6to4 update result was '$6to4OUT'"
:log info ("HE-UPD: Advertise eth2 again")
# Re-advertise IPv6 on internal interface 1
:local tmpHE1 [/ipv6 address find address="2001:470:xxxx:1::1/64"]
/ipv6 address set $tmpHE1 advertise=no
/ipv6 address set $tmpHE1 advertise=yes
:log info ("HE-UPD: Advertise eth3 again")
# Re-advertise IPv6 on internal interface 2
:local tmpHE2 [/ipv6 address find address="2001:470:xxxx:2::1/64"]
/ipv6 address set $tmpHE2 advertise=no
/ipv6 address set $tmpHE2 advertise=yes
# Refresh default route
:log info ("HE-UPD: Refresh default route")
/ipv6 route remove [/ipv6 route find dst-address="2000::/3"]
/ipv6 route add comment="" disabled=no distance=1 dst-address=2000::/3 gateway=2001:470:xxxx:xxxx::1 scope=30 target-scope=10
:log info ("HE-UPD: 6to4 update complete")
Tony