Diff

net/dns.lua @ 3746:9719316c854e

net.dns: Add resolver:tohostname() and dns.tohostname()
author Matthew Wild <mwild1@gmail.com>
date Tue, 14 Dec 2010 18:28:42 +0000
parent 3719:0f87632b87e9
child 3747:7d5b135bf268
line wrap: on
line diff
--- a/net/dns.lua	Mon Dec 13 20:45:08 2010 +0500
+++ b/net/dns.lua	Tue Dec 14 18:28:42 2010 +0000
@@ -939,6 +939,9 @@
 	return self:peek(qname, qtype, qclass) or self:query(qname, qtype, qclass);
 end
 
+function resolver:tohostname(ip)
+	return dns.lookup(ip:gsub("(%d+)%.(%d+)%.(%d+)%.(%d+)", "%4.%3.%2.%1.in-addr.arpa."), "PTR");
+end
 
 --print ---------------------------------------------------------------- print
 
@@ -1014,6 +1017,10 @@
 	return _resolver:lookup(...);
 end
 
+function dns.tohostname(...)
+	return _resolver:tohostname(...);
+end
+
 function dns.purge(...)    -- - - - - - - - - - - - - - - - - - - - - -  purge
 	return _resolver:purge(...);
 end