1 -- | Helpers to perform DNS queries.
8 import qualified Data.ByteString.Char8 as BS (
23 -- | Convert the given IP address (as a ByteString) to the format
24 -- required for a PTR lookup. For example, "192.168.0.0" should be
25 -- converted to "0.0.168.192.in-addr.arpa".
26 ip_to_in_addr_arpa :: Domain -> Domain
27 ip_to_in_addr_arpa ip =
28 rev_ip `BS.append` suffix
31 suffix = BS.pack ".in-addr.arpa"
32 rev_ip = BS.intercalate dot (reverse (BS.split '.' ip))
34 -- | Take the default ResolvConf and increase the timeout to 15
36 our_resolv_conf :: ResolvConf
38 defaultResolvConf { resolvTimeout = 15*1000*1000 } -- 15s
41 -- | Takes a list of IP addresses (as ByteStrings) and performs
42 -- reverse (PTR) lookups on each of them.
43 lookup_ptrs :: [Domain] -> IO [Maybe [Domain]]
45 rs <- makeResolvSeed our_resolv_conf
46 withResolver rs $ \resolver ->
47 mapM (lookupPTR resolver) in_addrs
49 in_addrs = map ip_to_in_addr_arpa ips