[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: DNS library for Lua
- From: Sean Conner <sean@...>
- Date: Tue, 7 Dec 2010 02:59:27 -0500
I just released a C library to encode/decode DNS queries (it also contains
a simple routine to send a query to a DNS server but that is seriously
stupid for real work) and I've included Lua bindings.
http://www.conman.org/software/spcdns/
A sample script:
local dns = require "org.conman.dns"
local SERVER = "127.0.0.1"
encode = dns.encode {
id = math.random(),
query = true,
rd = true, -- recursion desired
opcode = 'query',
question = {
name = "conman.org.", -- FQDN required
type = "LOC", -- LOC rr
class = "IN"
}
}
if encode == nil then
print("error")
os.exit(1)
end
data = dns.query(SERVER,encode)
if data == nil then
print("error")
os.exit(1)
end
reply = dns.decode(data)
if reply == nil then
print("error")
os.exit(1)
end
if #reply.answers > 0 then
print(string.format([[
Latitude: %3d %2d %2d %s
Longitude: %3d %2d %2d %s
Altitude: %d
]],
reply.answers[1].latitude.deg,
reply.answers[1].latitude.min,
reply.answers[1].latitude.sec,
reply.answers[1].latitude.hemisphere,
reply.answers[1].longitude.deg,
reply.answers[1].longitude.min,
reply.answers[1].longitude.sec,
reply.answers[1].longitude.hemisphere,
reply.answers[1].altitude
))
end
This isn't to say it doesn't support other record types, it does, such as
A, AAAA, MX, SOA, PTR, SRV, TXT, SPF, NAPTR and a whole bunch of other
records.
Questions, comments and criticisms are welcome.
-spc (Thought this might be of interest to the Lua community)