Created
March 19, 2015 00:11
-
-
Save mdunsmuir/3b30a7bf99f524a3e924 to your computer and use it in GitHub Desktop.
This file contains 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
import System.Environment | |
import Control.Exception | |
import Control.Monad | |
import Network.Socket | |
main = do | |
args <- getArgs | |
case args of | |
[host] -> catch (displayIPs host) $ \e -> do | |
let err = show (e :: IOException) | |
putStrLn $ "couldn't look up host " ++ host ++ " (" ++ err ++ ")" | |
_ -> fail "usage: ShowIP <hostname>" | |
displayIPs :: String -> IO () | |
displayIPs host = do | |
let query = defaultHints { addrFamily = AF_INET, addrSocketType = Stream } | |
infos <- getAddrInfo (Just query) (Just host) Nothing | |
forM_ infos (putStrLn . show) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment