ip2proxy 3.2.1 → 3.3.0
raw patch · 5 files changed
+45/−24 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ IP2Proxy: [fraud_score] :: IP2ProxyRecord -> String
+ IP2Proxy: getFraudScore :: String -> Meta -> String -> IO String
- IP2Proxy: IP2ProxyRecord :: String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> Int -> IP2ProxyRecord
+ IP2Proxy: IP2ProxyRecord :: String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> String -> Int -> IP2ProxyRecord
Files
- ChangeLog.md +4/−0
- IP2Proxy.hs +38/−21
- IP2ProxyWebService.hs +1/−1
- LICENSE +1/−1
- ip2proxy.cabal +1/−1
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for ip2proxy +## 3.3.0 -- 2025-02-18++* Added support for fraud score.+ ## 3.2.1 -- 2024-12-04 * Fixed boundary cases. Fixed IPv6 address error when using IPv4 BIN.
IP2Proxy.hs view
@@ -1,7 +1,7 @@ {-| Module : IP2Proxy Description : IP2Proxy Haskell package -Copyright : (c) IP2Location, 2018 - 2024 +Copyright : (c) IP2Location, 2018 - 2025 License : MIT Maintainer : sales@ip2location.com Stability : experimental @@ -10,7 +10,7 @@ IP2Proxy LITE BIN databases are available for free at http://lite.ip2location.com/ -} -module IP2Proxy (Meta, IP2ProxyRecord(..), getModuleVersion, getPackageVersion, getDatabaseVersion, open, getAll, getCountryShort, getCountryLong, getRegion, getCity, getISP, getProxyType, getDomain, getUsageType, getASN, getAS, getLastSeen, getThreat, getProvider, isProxy) where +module IP2Proxy (Meta, IP2ProxyRecord(..), getModuleVersion, getPackageVersion, getDatabaseVersion, open, getAll, getCountryShort, getCountryLong, getRegion, getCity, getISP, getProxyType, getDomain, getUsageType, getASN, getAS, getLastSeen, getThreat, getProvider, getFraudScore, isProxy) where import qualified Data.ByteString.Lazy as BS import qualified Data.ByteString.Lazy.Char8 as BS8 @@ -49,6 +49,8 @@ threat :: String, -- | Provider provider :: String, + -- | Fraud score + fraud_score :: String, -- | Is proxy is_proxy :: Int } deriving (Show) @@ -117,7 +119,7 @@ The 'getModuleVersion' function returns a string containing the module version. -} getModuleVersion :: String -getModuleVersion = "3.2.1" +getModuleVersion = "3.3.0" {-| The 'getPackageVersion' function returns a string containing the package version. @@ -210,18 +212,19 @@ readrecord :: BS.ByteString -> Int -> Int -> Int -> IP2ProxyRecord readrecord contents dbtype rowoffset mode = do - let country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] - let region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4] - let city_position = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5] - let isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6] - let proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] - let domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7] - let usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8] - let asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9] - let as_position = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10] - let lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11] - let threat_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12] - let provider_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13] + let country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3] + let region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4] + let city_position = [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5] + let isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6] + let proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2] + let domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7] + let usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8] + let asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9, 9] + let as_position = [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10, 10] + let lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11, 11] + let threat_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12, 12] + let provider_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13, 13] + let fraudscore_position = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14] let countryshort_field = 1 let countrylong_field = 2 @@ -237,8 +240,9 @@ let lastseen_field = 2048 let threat_field = 4096 let provider_field = 8192 + let fraudscore_field = 16384 - let allcols = (take 1 (drop dbtype country_position)) ++ (take 1 (drop dbtype region_position)) ++ (take 1 (drop dbtype city_position)) ++ (take 1 (drop dbtype isp_position)) ++ (take 1 (drop dbtype proxytype_position)) ++ (take 1 (drop dbtype domain_position)) ++ (take 1 (drop dbtype usagetype_position)) ++ (take 1 (drop dbtype asn_position)) ++ (take 1 (drop dbtype as_position)) ++ (take 1 (drop dbtype lastseen_position)) ++ (take 1 (drop dbtype threat_position)) ++ (take 1 (drop dbtype provider_position)) + let allcols = (take 1 (drop dbtype country_position)) ++ (take 1 (drop dbtype region_position)) ++ (take 1 (drop dbtype city_position)) ++ (take 1 (drop dbtype isp_position)) ++ (take 1 (drop dbtype proxytype_position)) ++ (take 1 (drop dbtype domain_position)) ++ (take 1 (drop dbtype usagetype_position)) ++ (take 1 (drop dbtype asn_position)) ++ (take 1 (drop dbtype as_position)) ++ (take 1 (drop dbtype lastseen_position)) ++ (take 1 (drop dbtype threat_position)) ++ (take 1 (drop dbtype provider_position)) ++ (take 1 (drop dbtype fraudscore_position)) let cols = (countif (>0) allcols) `shiftL` 2 let row = BS.take (fromIntegral cols) (BS.drop (fromIntegral rowoffset - 1) contents) @@ -290,13 +294,17 @@ then readcolstringrow contents row dbtype provider_position else "" + let fraud_score = if ((.&.) mode fraudscore_field) /= 0 + then readcolstringrow contents row dbtype fraudscore_position + else "" + let is_proxy = if (country_short == "-") || (proxy_type == "-") then 0 else if (proxy_type == "DCH") || (proxy_type == "SES") then 2 else 1 - IP2ProxyRecord country_short country_long region city isp proxy_type domain usage_type asn as last_seen threat provider is_proxy + IP2ProxyRecord country_short country_long region city isp proxy_type domain usage_type asn as last_seen threat provider fraud_score is_proxy searchtree :: BS.ByteString -> Integer -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> IP2ProxyRecord searchtree contents ipnum dbtype low high baseaddr colsize iptype mode = do @@ -328,7 +336,7 @@ searchtree contents ipnum dbtype (mid + 1) high baseaddr colsize iptype mode else do let x = "INVALID IP ADDRESS" - IP2ProxyRecord x x x x x x x x x x x x x (-1) + IP2ProxyRecord x x x x x x x x x x x x x x (-1) search4 :: BS.ByteString -> Integer -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> IP2ProxyRecord search4 contents ipnum dbtype low high baseaddr indexbaseaddr colsize mode = do @@ -372,7 +380,7 @@ -} getAll :: String -> Meta -> String -> IO IP2ProxyRecord getAll myfile meta myip = do - result <- doQuery myfile meta myip 16383 + result <- doQuery myfile meta myip 32767 return result {-| @@ -493,6 +501,15 @@ return (show (provider result)) {-| + The 'getFraudScore' function returns the fraud score for the IP. + It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String). +-} +getFraudScore :: String -> Meta -> String -> IO String +getFraudScore myfile meta myip = do + result <- doQuery myfile meta myip 16384 + return (show (fraud_score result)) + +{-| The 'isProxy' function returns 0 if IP is not a proxy, 1 if is a proxy and not data center IP, 2 if is a proxy and is a data center IP, -1 if error. It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String). -} @@ -518,7 +535,7 @@ if ipnum == -1 then do let x = "INVALID IP ADDRESS" - return $ IP2ProxyRecord x x x x x x x x x x x x x (-1) + return $ IP2ProxyRecord x x x x x x x x x x x x x x (-1) else if ipnum >= fromV4Mapped && ipnum <= toV4Mapped then do return $ search4 contents (ipnum - (toInteger fromV4Mapped)) (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode @@ -534,6 +551,6 @@ else if (ipv6databasecount meta) == 0 then do let x = "IPV6 ADDRESS MISSING IN IPV4 BIN" - return $ IP2ProxyRecord x x x x x x x x x x x x x (-1) + return $ IP2ProxyRecord x x x x x x x x x x x x x x (-1) else do return $ search6 contents ipnum (databasetype meta) 0 (ipv6databasecount meta) (ipv6databaseaddr meta) (ipv6indexbaseaddr meta) (ipv6columnsize meta) mode
IP2ProxyWebService.hs view
@@ -2,7 +2,7 @@ {-| Module : IP2ProxyWebService Description : IP2Proxy Haskell package -Copyright : (c) IP2Location, 2018 - 2024 +Copyright : (c) IP2Location, 2018 - 2025 License : MIT Maintainer : sales@ip2location.com Stability : experimental
LICENSE view
@@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 - 2024 IP2Location.com +Copyright (c) 2018 - 2025 IP2Location.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
ip2proxy.cabal view
@@ -10,7 +10,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change -version: 3.2.1 +version: 3.3.0 -- A short (one-line) description of the package. synopsis: IP2Proxy Haskell package for proxy detection.