-- | Helpers to perform DNS queries.
module DNS (
Domain,
- lookup_ptrs
- )
+ PTRResult,
+ lookup_ptrs )
where
+import Control.Concurrent.ParallelIO.Global ( parallel )
import qualified Data.ByteString.Char8 as BS (
append,
intercalate,
split )
import Network.DNS (
Domain,
+ DNSError,
ResolvConf(..),
defaultResolvConf,
lookupPTR,
makeResolvSeed,
- withResolver
- )
+ withResolver )
+
+
+-- The return type of lookupPTR.
+type PTRResult = Either DNSError [Domain]
-- | Convert the given IP address (as a ByteString) to the format
-- | Takes a list of IP addresses (as ByteStrings) and performs
-- reverse (PTR) lookups on each of them.
-lookup_ptrs :: [Domain] -> IO [Maybe [Domain]]
+lookup_ptrs :: [Domain] -> IO [PTRResult]
lookup_ptrs ips = do
rs <- makeResolvSeed our_resolv_conf
- withResolver rs $ \resolver ->
- mapM (lookupPTR resolver) in_addrs
+ let lookup' addr = withResolver rs $ \resolver ->
+ lookupPTR resolver addr
+
+ parallel $ map lookup' in_addrs
+
where
in_addrs = map ip_to_in_addr_arpa ips