Skip to content

Instantly share code, notes, and snippets.

@jasonrahm
Created November 18, 2020 05:08
Show Gist options
  • Save jasonrahm/59a6b26f8c82ebe62a13dde8e5b671bd to your computer and use it in GitHub Desktop.
Save jasonrahm/59a6b26f8c82ebe62a13dde8e5b671bd to your computer and use it in GitHub Desktop.
Example to do reverse lookups on IP addresses using the RESOLVER::name_lookup command, which replaces the deprecated RESOLV::lookup.
#####################################################
### Required net resolver - example configuration ###
#####################################################
#net dns-resolver r1 {
# forward-zones {
# . {
# nameservers {
# 8.8.8.8:domain { }
# 9.9.9.9:domain { }
# }
# }
# }
# route-domain 0
#}
# Proc to reverse the IP octets to build the ptr record format
# Downwards compatibility to 8.4: https://wiki.tcl-lang.org/page/lreverse
proc lreverse list {
set res {}
set i [llength $list]
while {$i} {
lappend res [lindex $list [incr i -1]]
}
set res
}
when CLIENT_ACCEPTED {
set tst_ip 54.230.18.2
# Format the ptr record so the RESOLVER::name_lookup will work properly for a ptr lookup
set ptr [join [call lreverse [split $tst_ip .]] .].in-addr.arpa
set result [RESOLVER::name_lookup "/Common/r1" $ptr ptr]
foreach rr [RESOLVER::summarize $result] {
log local0.debug [lindex $rr 4]
}
}
# Result:
# Nov 17 22:59:01 ltm3 debug tmm1[88844]: Rule /Common/resolver_demo <CLIENT_ACCEPTED>: server-54-230-18-2.ord51.r.cloudfront.net
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment