Created
May 19, 2019 20:10
-
-
Save ijsf/dd24bb595181209be3395a933e47bf70 to your computer and use it in GitHub Desktop.
PowerDNS recursor - on demand A record generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- PowerDNS on demand A record generator | |
-- | |
-- Resolves any record with format A-B-C-D.yourdomain.com to an A record with ip address A.B.C.D. | |
-- | |
pdnslog("pdns-recursor - on demand A record generator script loaded", pdns.loglevels.Warning) | |
domain = newDN("yourdomain.com") | |
function preresolve(dq) | |
if dq.qname:isPartOf(domain) then | |
qname = dq.qname:toStringNoDot() | |
pdnslog("Received query for '" .. qname .. "' from remote address " .. dq.remoteaddr:toString()) | |
-- Extract IP address using format: A-B-C-D.domain | |
it = string.gmatch(qname, "(%d+).") | |
ipAddress = '' | |
for i = 0, 3 do | |
octet = tonumber(it()) | |
-- Attempt 8-bit digit extraction | |
if octet >= 0 and octet <= 255 then | |
ipAddress = (i == 0) and (octet) or (ipAddress .. '.' .. octet) | |
else | |
-- Graceful failure | |
return true | |
end | |
end | |
-- Returns extracted IP address as A record | |
dq:addAnswer(pdns.A, ipAddress) | |
end | |
return true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment