cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
4091
Views
5
Helpful
2
Replies

Dyndns Update Script

Andrea Florio
Level 1
Level 1

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.

1 Accepted Solution

Accepted Solutions

Joe Clarke
Cisco Employee
Cisco Employee

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

View solution in original post

2 Replies 2

Joe Clarke
Cisco Employee
Cisco Employee

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

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

set url  "http://members.dyndns.org/nic/update?hostname=$fqdn&myip=$ipinterface&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"

# 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