06-02-2013 07:11 AM
Hello all,
using the old script to udate Hurricane Electric ipv6 tunnel end point i ended up making this one for dyndns.
the reason why is that lot's of time just a virtual interface goes down and the dns is not updated using the ddns method.
Here is the code:
#-------------------------------------------------------------------------------------
# EEM policy which updates the ipv4 or DynDNS
#
# expected syslog messages:
# %HA_EM-6-LOG: ddns.tcl: http request failed
# %HA_EM-6-LOG: ddns.tcl: Response: nochg <ip add>
# %HA_EM-6-LOG: ddns.tcl: Response: good <ip add>
#
# ddns.tcl
#
#-------------------------------------------------------------------------------------
::cisco::eem::event_register_none maxrun 300 queue_priority low nice 0
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set user "USERNAME"
set pass "PASSWORD"
set fqdn "FQDN"
set url "http://members.dyndns.org/nic/update?hostname=$fqdn&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
set auth "Basic [base64::encode $user:$pass]"
set headerl [list Authorization $auth]
if {[catch {http::geturl $url -headers $headerl -queryblocksize 50 -type "text/plain" } token]} {
action_syslog priority info msg "http request failed"
} else {
action_syslog priority info msg "Response: [http::data $token]"
}
exit 0
I would actually want to improve it, adding the myip= argument. This would be needed in case more than one interface needs to be tracked.
i would like to do something like:
set interface "Full interface name"
set url "http://members.dyndns.org/nic/update?hostname=$fqdn&myip=$ipinterface&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
i'm just not sure how to do get the ip address of the interface.
Solved! Go to Solution.
06-02-2013 08:52 AM
Best thing to do is CLI commands like you would do manually. Processing "show interface INTF | inc Internet address is" is a good way to do it.
if [catch {cli_open} result] { error $result $errorInfo } else { array set cli1 $result } if [catch {cli_exec $cli1(fd) "show int INTF | inc Internet address is"} _cli_result] { error $_cli_result $errorInfo } set _regexp_result [regexp {Internet address is ([\d\.]+)} $_cli_result match addr]
if { $_regexp_result == 0 } {
puts "Interface INTF does not have an IP address"
exit 1
}
set ipinterface $addr
set url ...
# Close open cli before exit. catch {cli_close $cli1(fd) $cli1(tty_id)} result
06-02-2013 08:52 AM
Best thing to do is CLI commands like you would do manually. Processing "show interface INTF | inc Internet address is" is a good way to do it.
if [catch {cli_open} result] { error $result $errorInfo } else { array set cli1 $result } if [catch {cli_exec $cli1(fd) "show int INTF | inc Internet address is"} _cli_result] { error $_cli_result $errorInfo } set _regexp_result [regexp {Internet address is ([\d\.]+)} $_cli_result match addr]
if { $_regexp_result == 0 } {
puts "Interface INTF does not have an IP address"
exit 1
}
set ipinterface $addr
set url ...
# Close open cli before exit. catch {cli_close $cli1(fd) $cli1(tty_id)} result
06-02-2013 11:23 AM
Hello Joseph,
Thank you so much, it's working
that's how the whole script would look like:
::cisco::eem::event_register_none maxrun 300 queue_priority low nice 0
namespace import ::cisco::eem::*
namespace import ::cisco::lib::*
set user "USERNAME"
set pass "PASSWORD"
set fqdn "FQDN"
if [catch {cli_open} result] {
error $result $errorInfo
} else {
array set cli1 $result
}
if [catch {cli_exec $cli1(fd) "show int INTERFACE | i Internet address is"} _cli_result] {
error $_cli_result $errorInfo
}
set _regexp_result [regexp {Internet address is ([\d\.]+)} $_cli_result match addr]
if { $_regexp_result == 0 } {
puts "Interface INTERFACE does not have an IP address"
exit 1
}
set ipinterface $addr
# Close open cli before exit.
catch {cli_close $cli1(fd) $cli1(tty_id)} result
set auth "Basic [base64::encode $user:$pass]"
set headerl [list Authorization $auth]
if {[catch {http::geturl $url -headers $headerl -queryblocksize 50 -type "text/plain" } token]} {
action_syslog priority info msg "http request failed"
} else {
action_syslog priority info msg "Response: [http::data $token]"
}
exit 0
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide