DNS is an internet service that maps domain names, like rosettacode.org, to IP addresses, like 66.220.0.231.

Use DNS to resolve www.kame.net to both IPv4 and IPv6 addresses. Print these addresses.




module Main where
 
import Network.Socket
 
getWebAddresses :: HostName -> IO [SockAddr]
getWebAddresses host = do
  results <- getAddrInfo (Just defaultHints) (Just host) (Just "http")
  return [ addrAddress a | a <- results, addrSocketType a == Stream ]
 
showIPs :: HostName -> IO ()
showIPs host = do
  putStrLn $ "IP addresses for " ++ host ++ ":"
  addresses <- getWebAddresses host
  mapM_ (putStrLn . ("  "++) . show) addresses
 
main = showIPs "www.kame.net"
 