Created
March 19, 2015 00:11
-
-
Save mdunsmuir/3b30a7bf99f524a3e924 to your computer and use it in GitHub Desktop.
Revisions
-
mdunsmuir created this gist
Mar 19, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,18 @@ 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)