Skip to content

Instantly share code, notes, and snippets.

@atomizer
Created November 4, 2012 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomizer/4009664 to your computer and use it in GitHub Desktop.
Save atomizer/4009664 to your computer and use it in GitHub Desktop.
dns host pack
function enc(s) {
if (!s) throw new Error('need hostname')
if (s.slice(-1) != '.') s += '.'
var r = Buffer(s.length + 1)
s = s.split('.')
var cc = 0
for (var i = 0; i < s.length; i++) {
r.writeUInt8(s[i].length, cc)
cc++
r.write(s[i], cc)
cc += s[i].length
}
return r.toString('hex')
}
console.log(enc(process.argv[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment