iproute
iproute copied to clipboard
Add parse from ByteString
Add parse from ByteString and Text
Are you talking about IP
?
Yes. I parse very big apache log files and find each IP in RouteTable.
OK. Could you implement it by yourself and give me a pull request?
I work throuth 4Int list:
import Control.Applicative
import Data.Attoparsec.ByteString
import qualified Data.ByteString.Char8 as BC
import Data.ByteString.Internal (c2w)
ip2list :: BC.ByteString -> [Int]
ip2list ipstr =
case parseOnly pIP2list ipstr of
Left msg -> error msg
Right ip -> ip
pIP2list :: Parser [Int]
pIP2list = toIP <$> dd <*> dd <*> dd <*> dig
where
toIP a b c d = [a, b, c, d]
dig = AC.decimal
dd = dig <* skip (== c2w '.')
And my ipFilter:
ipFiltr :: IPRTable IPv4 () -> LogLine -> Bool
ipFiltr bans
= DM.isNothing . flip lookup bans
. flip makeAddrRange 32 . toIPv4 . ip2list . getLogIP