Skip to content

Instantly share code, notes, and snippets.

@mdunsmuir
Created March 19, 2015 00:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdunsmuir/3b30a7bf99f524a3e924 to your computer and use it in GitHub Desktop.
Save mdunsmuir/3b30a7bf99f524a3e924 to your computer and use it in GitHub Desktop.
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