ip6addr 0.5.2 → 0.5.3
raw patch · 3 files changed
+100/−93 lines, 3 filesdep ~IPv6Addr
Dependency ranges changed: IPv6Addr
Files
- LICENSE +1/−1
- Main.hs +71/−66
- ip6addr.cabal +28/−26
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015, Michel Boucey+Copyright (c) 2015-2017, Michel Boucey. All rights reserved.
Main.hs view
@@ -12,78 +12,83 @@ import Text.IPv6Addr +version :: String+version = "0.5.2"+ data Input = Input- { output :: String- , address :: String- , quantity :: Int- , prefix :: String- } deriving (Show, Data, Typeable)+ { output :: String+ , address :: String+ , quantity :: Int+ , prefix :: String+ } deriving (Show, Data, Typeable) ip6addrInput :: Input ip6addrInput = Input- { address = ""- &= typ " <IPv6 address>"- , output = "canonical"- &= typ " [canonical|pure|full|arpa|unc|random]"- &= help "Default : canonical (RFC 5952)"- , quantity = 1- &= help "Amount of random addresses to generate"- &= typ " <Integer>"- , prefix = ""- &= typ " <Prefix>"- &= help "Set a prefix for random addresses generation"- } &= summary "ip6addr version 0.5.1.4 (c) Michel Boucey 2015-2016"- &= program "ip6addr"- &= helpArg [name "h"]- &= details [ "Examples:"- , ""- , " ip6addr -a 0:0::FFFF:192.0.2.128"- , " ip6addr -o full -a ::1"- , " ip6addr -o random -q 10 -p 1234:abcd::"- , ""- ]+ { address = mempty+ &= typ " <IPv6 address>"+ , output = "canonical"+ &= typ " [canonical|pure|full|arpa|unc|random]"+ &= help "Default : canonical (RFC 5952)"+ , quantity = 1+ &= help "Amount of random addresses to generate"+ &= typ " <Integer>"+ , prefix = ""+ &= typ " <Prefix>"+ &= help "Set a prefix for random addresses generation"+ } &= summary ("ip6addr version " <> version <> " (c) Michel Boucey 2015-2017")+ &= program "ip6addr"+ &= helpArg [name "h"]+ &= details [ "Examples:"+ , ""+ , " ip6addr -a 0:0::FFFF:192.0.2.128"+ , " ip6addr -o full -a ::1"+ , " ip6addr -o random -q 10 -p 1234:abcd::"+ , ""+ ] main :: IO () main = do- Input {..} <- cmdArgs ip6addrInput- if output == "random"- then replicateM_ quantity (putRandAddr prefix) >> exitSuccess- else case output of- "canonical" -> out maybeIPv6Addr address fromIPv6Addr- "pure" -> out maybePureIPv6Addr address fromIPv6Addr- "full" -> out maybeFullIPv6Addr address fromIPv6Addr- "arpa" -> out maybeIP6ARPA address id- "unc" -> out maybeUNC address id- _ -> TIO.hPutStrLn stderr "See help" >> exitFailure+ Input{..} <- cmdArgs ip6addrInput+ if output == "random"+ then replicateM_ quantity (putRandAddr prefix) >> exitSuccess+ else+ case output of+ "canonical" -> out maybeIPv6Addr address fromIPv6Addr+ "pure" -> out maybePureIPv6Addr address fromIPv6Addr+ "full" -> out maybeFullIPv6Addr address fromIPv6Addr+ "arpa" -> out maybeIP6ARPA address id+ "unc" -> out maybeUNC address id+ _ -> TIO.hPutStrLn stderr "See help" >> exitFailure where- putRandAddr p = do- r <- randIPv6AddrWithPrefix $- if p == "" then Nothing else Just $ T.pack p- case r of- Nothing -> TIO.putStrLn "Bad prefix"- Just a -> TIO.putStrLn $ fromIPv6Addr a- out t i o =- if i /= ""- then do- let p = T.pack i- case t p of- Nothing -> TIO.hPutStrLn stderr- ("'" <> p <> "' is not an IPv6 address")- >> exitFailure- Just a -> TIO.putStrLn (o a) >> exitSuccess- else Prelude.putStrLn "See help" >> exitFailure- maybeUNC t =- maybe Nothing- (\a -> Just $ (T.concatMap trans $ fromIPv6Addr a) <> ".ipv6-literal.net")- (maybePureIPv6Addr t)- where- trans ':' = "-"- trans c = T.pack [c]- maybeIP6ARPA t =- maybe Nothing- (\a -> Just $ T.reverse (T.concatMap trans $ fromIPv6Addr a) <> "IP6.ARPA.")- (maybeFullIPv6Addr t)- where- trans ':' = T.empty- trans c = "." <> T.pack [c]+ putRandAddr p = do+ r <- randIPv6AddrWithPrefix (if p == mempty then Nothing else Just (T.pack p))+ case r of+ Nothing -> TIO.putStrLn "Bad prefix"+ Just a -> TIO.putStrLn (fromIPv6Addr a)+ out t i o =+ if i /= mempty+ then do+ let p = T.pack i+ case t p of+ Nothing ->+ TIO.hPutStrLn stderr ("'" <> p <> "' is not an IPv6 address")+ >> exitFailure+ Just a -> TIO.putStrLn (o a) >> exitSuccess+ else Prelude.putStrLn "See help" >> exitFailure+ maybeUNC t =+ maybe+ Nothing+ (\a -> Just (T.concatMap trans (fromIPv6Addr a) <> ".ipv6-literal.net"))+ (maybePureIPv6Addr t)+ where+ trans ':' = "-"+ trans c = T.pack [c]+ maybeIP6ARPA t =+ maybe+ Nothing+ (\a -> Just (T.reverse (T.concatMap trans (fromIPv6Addr a)) <> "IP6.ARPA."))+ (maybeFullIPv6Addr t)+ where+ trans ':' = T.empty+ trans c = "." <> T.pack [c]
ip6addr.cabal view
@@ -1,30 +1,32 @@-name: ip6addr-version: 0.5.2-synopsis: Commandline tool to generate IPv6 address text representations-description: Commandline tool to generate IPv6 address text representations-license: BSD3-license-file: LICENSE-author: Michel Boucey-maintainer: michel.boucey@cybervisible.fr-homepage: https://github.com/MichelBoucey/ip6addr-Copyright: Copyright (c) 2011-2016 - Michel Boucey-Category: Network,Console-build-type: Simple-cabal-version: >=1.10-extra-source-files: README.md+name: ip6addr+version: 0.5.3+cabal-version: >=1.10+build-type: Simple+license: BSD3+license-file: LICENSE+copyright: Copyright (c) 2011-2017 - Michel Boucey+maintainer: michel.boucey@cybervisible.fr+homepage: https://github.com/MichelBoucey/ip6addr+synopsis: Commandline tool to generate IPv6 address text representations+description:+ Commandline tool to generate IPv6 address text representations+category: Network,Console+author: Michel Boucey+extra-source-files:+ README.md -Source-Repository head- Type: git- Location: https://github.com/MichelBoucey/ip6addr.git+source-repository head+ type: git+ location: https://github.com/MichelBoucey/ip6addr.git executable ip6addr- main-is: Main.hs- other-extensions: DeriveDataTypeable- , OverloadedStrings- build-depends: base >= 4.7 && < 5- , cmdargs >= 0.10.13 && < 0.11- , IPv6Addr >= 0.6.0.2 && < 0.7- , text >= 1.2.2 && < 1.3- default-language: Haskell2010- GHC-Options: -Wall+ main-is: Main.hs+ build-depends:+ base >=4.8 && <5,+ cmdargs >=0.10.13 && <0.11,+ IPv6Addr >=0.6.0.2 && <1.1.0,+ text >=1.2.2 && <1.3+ default-language: Haskell2010+ other-extensions: DeriveDataTypeable OverloadedStrings+ ghc-options: -Wall