Skip to content

Commit 5f800fb

Browse files
Added functions that allow the opening of the BIN file once and querying multiple times.
1 parent 31730f5 commit 5f800fb

9 files changed

Lines changed: 252 additions & 47 deletions

File tree

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Revision history for ip2proxy
22

3+
## 3.4.0 -- 2026-01-12
4+
5+
* Added functions that allow the opening of the BIN file once and querying multiple times.
6+
37
## 3.3.0 -- 2025-02-18
48

59
* Added support for fraud score.

IP2Proxy.hs

Lines changed: 197 additions & 3 deletions
Large diffs are not rendered by default.

IP2ProxyWebService.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{-|
33
Module : IP2ProxyWebService
44
Description : IP2Proxy Haskell package
5-
Copyright : (c) IP2Location, 2018 - 2025
5+
Copyright : (c) IP2Location, 2018 - 2026
66
License : MIT
77
Maintainer : sales@ip2location.com
88
Stability : experimental

LICENSE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-2026 IP2Location.com
3+
Copyright (c) 2018 - 2026 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-

docs/source/code.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# IP2Proxy Haskell API
22

33
## IP2Proxy Class
4-
```{py:function} open(binpath)
4+
```{py:function} openBS(contents)
55
Load the IP2Proxy BIN database for lookup.
66
7-
:param str binpath: (Required) The file path links to IP2Proxy BIN databases.
7+
:param Data.ByteString.Lazy.ByteString contents: (Required) The IP2Proxy BIN database file content.
8+
:return: Returns the meta data in Record
9+
:rtype: Record
810
```
911

1012
```{py:function} getPackageVersion()
@@ -28,9 +30,11 @@ Return the database's compilation date as a string of the form 'YYYY-MM-DD'.
2830
:rtype: string
2931
```
3032

31-
```{py:function} getAll(ipAddress)
33+
```{py:function} getAllBS(contents, meta, ipAddress)
3234
Retrieve geolocation information for an IP address.
3335
36+
:param Data.ByteString.Lazy.ByteString contents: (Required) The IP2Proxy BIN database file content.
37+
:param Meta meta: (Required) The BIN file meta data.
3438
:param string ipAddress: (Required) The IP address (IPv4 or IPv6).
3539
:return: Returns the geolocation information in array. Refer below table for the fields avaliable in the array
3640
:rtype: array

docs/source/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
# -- Project information
55

66
project = 'IP2Proxy Haskell'
7-
copyright = '2025, IP2Location'
7+
copyright = '2026, IP2Location'
88
author = 'IP2Location'
99

10-
release = '0.1.0'
11-
version = '0.1.0'
10+
release = '3.4.0'
11+
version = '3.4.0'
1212

1313
# -- General configuration
1414

docs/source/quickstart.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@ You can query the geolocation information from the IP2Proxy BIN database as belo
2424

2525
```haskell
2626
import IP2Proxy
27+
import qualified Data.ByteString.Lazy as BS
2728

2829
main :: IO ()
2930
main = do
3031
let myfile = "./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER-FRAUDSCORE.BIN"
3132
let ip = "197.85.191.64"
32-
meta <- open myfile
33+
contents <- BS.readFile myfile -- load BIN once
34+
meta <- openBS contents
3335

3436
putStrLn $ "module_version: " ++ getModuleVersion
3537
putStrLn $ "package_version: " ++ (getPackageVersion meta)
3638
putStrLn $ "database_version: " ++ (getDatabaseVersion meta)
3739

38-
result <- getAll myfile meta ip
40+
result <- getAllBS contents meta ip
3941
putStrLn $ "country_short: " ++ (show (country_short result))
4042
putStrLn $ "country_long: " ++ (show (country_long result))
4143
putStrLn $ "region: " ++ (show (region result))
@@ -52,34 +54,34 @@ main = do
5254
putStrLn $ "fraud_score: " ++ (show (fraud_score result))
5355
putStrLn $ "is_proxy: " ++ (show (is_proxy result))
5456

55-
result <- getCountryShort myfile meta ip
57+
result <- getCountryShortBS contents meta ip
5658
putStrLn $ "country_short: " ++ result
57-
result <- getCountryLong myfile meta ip
59+
result <- getCountryLongBS contents meta ip
5860
putStrLn $ "country_long: " ++ result
59-
result <- getRegion myfile meta ip
61+
result <- getRegionBS contents meta ip
6062
putStrLn $ "region: " ++ result
61-
result <- getCity myfile meta ip
63+
result <- getCityBS contents meta ip
6264
putStrLn $ "city: " ++ result
63-
result <- getISP myfile meta ip
65+
result <- getISPBS contents meta ip
6466
putStrLn $ "isp: " ++ result
65-
result <- getProxyType myfile meta ip
67+
result <- getProxyTypeBS contents meta ip
6668
putStrLn $ "proxy_type: " ++ result
67-
result <- getDomain myfile meta ip
69+
result <- getDomainBS contents meta ip
6870
putStrLn $ "domain: " ++ result
69-
result <- getUsageType myfile meta ip
71+
result <- getUsageTypeBS contents meta ip
7072
putStrLn $ "usage_type: " ++ result
71-
result <- getASN myfile meta ip
73+
result <- getASNBS contents meta ip
7274
putStrLn $ "asn: " ++ result
73-
result <- getAS myfile meta ip
75+
result <- getASBS contents meta ip
7476
putStrLn $ "as: " ++ result
75-
result <- getLastSeen myfile meta ip
77+
result <- getLastSeenBS contents meta ip
7678
putStrLn $ "last_seen: " ++ result
77-
result <- getThreat myfile meta ip
79+
result <- getThreatBS contents meta ip
7880
putStrLn $ "threat: " ++ result
79-
result <- getProvider myfile meta ip
81+
result <- getProviderBS contents meta ip
8082
putStrLn $ "provider: " ++ result
81-
result <- getFraudScore myfile meta ip
83+
result <- getFraudScoreBS contents meta ip
8284
putStrLn $ "fraud_score: " ++ result
83-
result <- isProxy myfile meta ip
85+
result <- isProxyBS contents meta ip
8486
putStrLn $ "is_proxy: " ++ result
8587
```

ip2proxy.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name: ip2proxy
1010
-- PVP summary: +-+------- breaking API changes
1111
-- | | +----- non-breaking API additions
1212
-- | | | +--- code changes with no API change
13-
version: 3.3.0
13+
version: 3.4.0
1414

1515
-- A short (one-line) description of the package.
1616
synopsis: IP2Proxy Haskell package for proxy detection.

test.hs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
import IP2Proxy
2+
import qualified Data.ByteString.Lazy as BS
23

34
main :: IO ()
45
main = do
56
let myfile = "./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER-FRAUDSCORE.BIN"
67
let ip = "197.85.191.64"
7-
meta <- open myfile
8+
contents <- BS.readFile myfile -- load BIN once
9+
meta <- openBS contents
810

911
putStrLn $ "module_version: " ++ getModuleVersion
1012
putStrLn $ "package_version: " ++ (getPackageVersion meta)
1113
putStrLn $ "database_version: " ++ (getDatabaseVersion meta)
1214

13-
result <- getAll myfile meta ip
15+
result <- getAllBS contents meta ip
1416
putStrLn $ "country_short: " ++ (show (country_short result))
1517
putStrLn $ "country_long: " ++ (show (country_long result))
1618
putStrLn $ "region: " ++ (show (region result))
@@ -27,33 +29,33 @@ main = do
2729
putStrLn $ "fraud_score: " ++ (show (fraud_score result))
2830
putStrLn $ "is_proxy: " ++ (show (is_proxy result))
2931

30-
result <- getCountryShort myfile meta ip
32+
result <- getCountryShortBS contents meta ip
3133
putStrLn $ "country_short: " ++ result
32-
result <- getCountryLong myfile meta ip
34+
result <- getCountryLongBS contents meta ip
3335
putStrLn $ "country_long: " ++ result
34-
result <- getRegion myfile meta ip
36+
result <- getRegionBS contents meta ip
3537
putStrLn $ "region: " ++ result
36-
result <- getCity myfile meta ip
38+
result <- getCityBS contents meta ip
3739
putStrLn $ "city: " ++ result
38-
result <- getISP myfile meta ip
40+
result <- getISPBS contents meta ip
3941
putStrLn $ "isp: " ++ result
40-
result <- getProxyType myfile meta ip
42+
result <- getProxyTypeBS contents meta ip
4143
putStrLn $ "proxy_type: " ++ result
42-
result <- getDomain myfile meta ip
44+
result <- getDomainBS contents meta ip
4345
putStrLn $ "domain: " ++ result
44-
result <- getUsageType myfile meta ip
46+
result <- getUsageTypeBS contents meta ip
4547
putStrLn $ "usage_type: " ++ result
46-
result <- getASN myfile meta ip
48+
result <- getASNBS contents meta ip
4749
putStrLn $ "asn: " ++ result
48-
result <- getAS myfile meta ip
50+
result <- getASBS contents meta ip
4951
putStrLn $ "as: " ++ result
50-
result <- getLastSeen myfile meta ip
52+
result <- getLastSeenBS contents meta ip
5153
putStrLn $ "last_seen: " ++ result
52-
result <- getThreat myfile meta ip
54+
result <- getThreatBS contents meta ip
5355
putStrLn $ "threat: " ++ result
54-
result <- getProvider myfile meta ip
56+
result <- getProviderBS contents meta ip
5557
putStrLn $ "provider: " ++ result
56-
result <- getFraudScore myfile meta ip
58+
result <- getFraudScoreBS contents meta ip
5759
putStrLn $ "fraud_score: " ++ result
58-
result <- isProxy myfile meta ip
60+
result <- isProxyBS contents meta ip
5961
putStrLn $ "is_proxy: " ++ result

0 commit comments

Comments
 (0)