Skip to content

Instantly share code, notes, and snippets.

@andradefil
Created October 20, 2025 13:19
Show Gist options
  • Select an option

  • Save andradefil/5b658840d6fd65cd856d0dca47bea614 to your computer and use it in GitHub Desktop.

Select an option

Save andradefil/5b658840d6fd65cd856d0dca47bea614 to your computer and use it in GitHub Desktop.
Raw dns resolution in Clojure
(import '[java.net DatagramSocket DatagramPacket InetAddress])
(def query
(byte-array
[(byte 0x12) (byte 0x34) (byte 0x01) (byte 0x00)
(byte 0x00) (byte 0x01) (byte 0x00) (byte 0x00)
(byte 0x00) (byte 0x00) (byte 0x00) (byte 0x00)
(byte 0x07) (byte \c) (byte \l) (byte \o)
(byte \j) (byte \u) (byte \r) (byte \e)
(byte 0x03) (byte \o) (byte \r) (byte \g)
(byte 0x00) (byte 0x00) (byte 0x01) (byte 0x00)
(byte 0x01)]))
(let [sock (DatagramSocket.)
addr (InetAddress/getByName "8.8.8.8")
send (DatagramPacket. query (alength query) addr 53)
recv (DatagramPacket. (byte-array 512) 512)]
(.send sock send)
(.receive sock recv)
(println "Response length:" (.getLength recv))
(.close sock))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment