Skip to content

Instantly share code, notes, and snippets.

@jbarber
Created April 1, 2011 16:07
Show Gist options
  • Save jbarber/898398 to your computer and use it in GitHub Desktop.
Save jbarber/898398 to your computer and use it in GitHub Desktop.
Clojure dnsjava example for doing DNS updates
; Clojure example for updating a DNS zone using dnsjava 2.1.1:
; http://www.xbill.org/dnsjava/
; Tested against named 9.3.6 from Red Hat on RHEL5.4
; Run using: java -cp clojure.jar:dnsjava-2.1.1.jar clojure.main dns-update.clj
(import '(org.xbill.DNS Update Name Type TSIG SimpleResolver))
(defn replaceArec [resolver zone host ip ttl]
(let [update (Update. zone)]
(do
(. update replace
(Name. host zone)
Type/A
(long ttl)
ip)
(. resolver send update))))
(defn getres [ip tsig-keyname tsig-keyvalue]
(let [res (SimpleResolver. ip)]
(do
(. res setTSIGKey (TSIG. tsig-keyname tsig-keyvalue))
(. res setTCP true)
res)))
(let [zone (Name. "your.domain.com")
resolver (getres "ns0.your.domain.com" "tsig-key-name" "2Xrkq45HHMTR0Wh1+eF68Q==")
host "new-host-name"
ip "1.1.1.1"
ttl 86400
]
(replaceArec resolver zone host ip ttl))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment