Skip to content

Commit 6d93b0b

Browse files
committed
Added support for PX5 to PX8 packages
1 parent 87c3f3b commit 6d93b0b

28 files changed

+135
-1124
lines changed

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+
## 2.0.0 -- 2019-05-27
4+
5+
* Added support for PX5 to PX8 packages.
6+
37
## 1.0.0 -- 2018-11-29
48

59
* First version. Released on an unsuspecting world.

IP2Proxy.hs

Lines changed: 99 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{-|
22
Module : IP2Proxy
33
Description : IP2Proxy Haskell package
4-
Copyright : (c) IP2Location, 2018
4+
Copyright : (c) IP2Location, 2019
55
License : MIT
66
Maintainer : sales@ip2location.com
77
Stability : experimental
@@ -10,7 +10,7 @@ This Haskell package allows users to query an IP address to determine if it was
1010
1111
IP2Proxy LITE BIN databases are available for free at http://lite.ip2location.com/
1212
-}
13-
module IP2Proxy (Meta, IP2ProxyRecord(..), getModuleVersion, getPackageVersion, getDatabaseVersion, open, getAll, getCountryShort, getCountryLong, getRegion, getCity, getISP, getProxyType, isProxy) where
13+
module IP2Proxy (Meta, IP2ProxyRecord(..), getModuleVersion, getPackageVersion, getDatabaseVersion, open, getAll, getCountryShort, getCountryLong, getRegion, getCity, getISP, getProxyType, getDomain, getUsageType, getASN, getAS, getLastSeen, isProxy) where
1414

1515
import qualified Data.ByteString.Lazy as BS
1616
import qualified Data.ByteString.Lazy.Char8 as BS8
@@ -34,6 +34,16 @@ data IP2ProxyRecord = IP2ProxyRecord {
3434
isp :: String,
3535
-- | Proxy type
3636
proxy_type :: String,
37+
-- | Domain
38+
domain :: String,
39+
-- | Usage type
40+
usage_type :: String,
41+
-- | ASN
42+
asn :: String,
43+
-- | AS
44+
as :: String,
45+
-- | Last seen
46+
last_seen :: String,
3747
-- | Is proxy
3848
is_proxy :: Int
3949
} deriving (Show)
@@ -89,7 +99,7 @@ getMeta = do
8999
The 'getModuleVersion' function returns a string containing the module version.
90100
-}
91101
getModuleVersion :: String
92-
getModuleVersion = "1.0.0"
102+
getModuleVersion = "2.0.0"
93103

94104
{-|
95105
The 'getPackageVersion' function returns a string containing the package version.
@@ -173,19 +183,29 @@ readcolstring contents dbtype rowoffset col = do
173183

174184
readrecord :: BS.ByteString -> Int -> Int -> Int -> IP2ProxyRecord
175185
readrecord contents dbtype rowoffset mode = do
176-
let country_position = [0, 2, 3, 3, 3]
177-
let region_position = [0, 0, 0, 4, 4]
178-
let city_position = [0, 0, 0, 5, 5]
179-
let isp_position = [0, 0, 0, 0, 6]
180-
let proxytype_position = [0, 0, 2, 2, 2]
181-
186+
let country_position = [0, 2, 3, 3, 3, 3, 3, 3, 3]
187+
let region_position = [0, 0, 0, 4, 4, 4, 4, 4, 4]
188+
let city_position = [0, 0, 0, 5, 5, 5, 5, 5, 5]
189+
let isp_position = [0, 0, 0, 0, 6, 6, 6, 6, 6]
190+
let proxytype_position = [0, 0, 2, 2, 2, 2, 2, 2, 2]
191+
let domain_position = [0, 0, 0, 0, 0, 7, 7, 7, 7]
192+
let usagetype_position = [0, 0, 0, 0, 0, 0, 8, 8, 8]
193+
let asn_position = [0, 0, 0, 0, 0, 0, 0, 9, 9]
194+
let as_position = [0, 0, 0, 0, 0, 0, 0, 10, 10]
195+
let lastseen_position = [0, 0, 0, 0, 0, 0, 0, 0, 11]
196+
182197
let countryshort_field = 1
183198
let countrylong_field = 2
184199
let region_field = 4
185200
let city_field = 8
186201
let isp_field = 16
187202
let proxytype_field = 32
188203
let isproxy_field = 64
204+
let domain_field = 128
205+
let usagetype_field = 256
206+
let asn_field = 512
207+
let as_field = 1024
208+
let lastseen_field = 2048
189209

190210
let proxy_type = if (((.&.) mode proxytype_field) /= 0) || (((.&.) mode isproxy_field) /= 0)
191211
then readcolstring contents dbtype rowoffset proxytype_position
@@ -207,13 +227,33 @@ readrecord contents dbtype rowoffset mode = do
207227
then readcolstring contents dbtype rowoffset isp_position
208228
else ""
209229

230+
let domain = if ((.&.) mode domain_field) /= 0
231+
then readcolstring contents dbtype rowoffset domain_position
232+
else ""
233+
234+
let usage_type = if ((.&.) mode usagetype_field) /= 0
235+
then readcolstring contents dbtype rowoffset usagetype_position
236+
else ""
237+
238+
let asn = if ((.&.) mode asn_field) /= 0
239+
then readcolstring contents dbtype rowoffset asn_position
240+
else ""
241+
242+
let as = if ((.&.) mode as_field) /= 0
243+
then readcolstring contents dbtype rowoffset as_position
244+
else ""
245+
246+
let last_seen = if ((.&.) mode lastseen_field) /= 0
247+
then readcolstring contents dbtype rowoffset lastseen_position
248+
else ""
249+
210250
let is_proxy = if (country_short == "-") || (proxy_type == "-")
211251
then 0
212-
else if proxy_type == "DCH"
252+
else if (proxy_type == "DCH") || (proxy_type == "SES")
213253
then 2
214254
else 1
215255

216-
IP2ProxyRecord country_short country_long region city isp proxy_type is_proxy
256+
IP2ProxyRecord country_short country_long region city isp proxy_type domain usage_type asn as last_seen is_proxy
217257

218258
searchtree :: BS.ByteString -> Integer -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> IP2ProxyRecord
219259
searchtree contents ipnum dbtype low high baseaddr colsize iptype mode = do
@@ -245,7 +285,7 @@ searchtree contents ipnum dbtype low high baseaddr colsize iptype mode = do
245285
searchtree contents ipnum dbtype (mid + 1) high baseaddr colsize iptype mode
246286
else do
247287
let x = "INVALID IP ADDRESS"
248-
IP2ProxyRecord x x x x x x (-1)
288+
IP2ProxyRecord x x x x x x x x x x x (-1)
249289

250290
search4 :: BS.ByteString -> Integer -> Int -> Int -> Int -> Int -> Int -> Int -> Int -> IP2ProxyRecord
251291
search4 contents ipnum dbtype low high baseaddr indexbaseaddr colsize mode = do
@@ -281,7 +321,7 @@ tryfirst myIP = do
281321
-}
282322
getAll :: String -> Meta -> String -> IO IP2ProxyRecord
283323
getAll myfile meta myip = do
284-
result <- doQuery myfile meta myip 127
324+
result <- doQuery myfile meta myip 4095
285325
return result
286326

287327
{-|
@@ -338,6 +378,51 @@ getProxyType myfile meta myip = do
338378
result <- doQuery myfile meta myip 32
339379
return (show (proxy_type result))
340380

381+
{-|
382+
The 'getDomain' function returns the domain name for an IP address.
383+
It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String).
384+
-}
385+
getDomain :: String -> Meta -> String -> IO String
386+
getDomain myfile meta myip = do
387+
result <- doQuery myfile meta myip 128
388+
return (show (domain result))
389+
390+
{-|
391+
The 'getUsageType' function returns the usage type for an IP address.
392+
It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String).
393+
-}
394+
getUsageType :: String -> Meta -> String -> IO String
395+
getUsageType myfile meta myip = do
396+
result <- doQuery myfile meta myip 256
397+
return (show (usage_type result))
398+
399+
{-|
400+
The 'getASN' function returns the autonomous system number for an IP address.
401+
It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String).
402+
-}
403+
getASN :: String -> Meta -> String -> IO String
404+
getASN myfile meta myip = do
405+
result <- doQuery myfile meta myip 512
406+
return (show (asn result))
407+
408+
{-|
409+
The 'getAS' function returns the autonomous system name for an IP address.
410+
It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String).
411+
-}
412+
getAS :: String -> Meta -> String -> IO String
413+
getAS myfile meta myip = do
414+
result <- doQuery myfile meta myip 1024
415+
return (show (as result))
416+
417+
{-|
418+
The 'getLastSeen' function returns the number of days last seen for an IP address.
419+
It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String).
420+
-}
421+
getLastSeen :: String -> Meta -> String -> IO String
422+
getLastSeen myfile meta myip = do
423+
result <- doQuery myfile meta myip 2048
424+
return (show (last_seen result))
425+
341426
{-|
342427
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.
343428
It takes 3 arguments; the BIN database file path (String), the metadata from 'open' function (Meta record) & either IPv4 or IPv6 address (String).
@@ -359,7 +444,7 @@ doQuery myfile meta myip mode = do
359444
if ipnum == -1
360445
then do
361446
let x = "INVALID IP ADDRESS"
362-
return $ IP2ProxyRecord x x x x x x (-1)
447+
return $ IP2ProxyRecord x x x x x x x x x x x (-1)
363448
else if ipnum >= from && ipnum <= to
364449
then do
365450
return $ search4 contents (ipnum - (toInteger from)) (databasetype meta) 0 (ipv4databasecount meta) (ipv4databaseaddr meta) (ipv4indexbaseaddr meta) (ipv4columnsize meta) mode

LICENSE

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

3-
Copyright (c) 2018 IP2Location.com
3+
Copyright (c) 2019 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

README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# IP2Proxy Haskell Module
22

3-
This Haskell package allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
3+
This Haskell package allows user to query an IP address if it was being used as VPN anonymizer, open proxies, web proxies, Tor exits, data center, web hosting (DCH) range and search engine robots (SES). It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
44

5-
* Free IP2Proxy BIN Data: http://lite.ip2location.com
6-
* Commercial IP2Proxy BIN Data: http://www.ip2location.com/proxy-database
5+
* Free IP2Proxy BIN Data: https://lite.ip2location.com
6+
* Commercial IP2Proxy BIN Data: https://www.ip2location.com/database/ip2proxy
77

88

99
## Installation
@@ -18,17 +18,22 @@ Below are the methods supported in this package.
1818
|Method Name|Description|
1919
|---|---|
2020
|open|Open the IP2Proxy BIN data for lookup.|
21-
|getPackageVersion|Get the package version (1 to 4 for PX1 to PX4 respectively).|
21+
|getPackageVersion|Get the package version (1 to 8 for PX1 to PX8 respectively).|
2222
|getModuleVersion|Get the module version.|
2323
|getDatabaseVersion|Get the database version.|
24-
|isProxy|Check whether if an IP address was a proxy. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address</li></ul>|
24+
|isProxy|Check whether if an IP address was a proxy. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address or search engine robot</li></ul>|
2525
|getAll|Return the proxy information in a record.|
26-
|getProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/databases/px4-ip-proxytype-country-region-city-isp" target="_blank">IP2Location</a> for the list of proxy types supported|
26+
|getProxyType|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of proxy types supported.|
2727
|getCountryShort|Return the ISO3166-1 country code (2-digits) of the proxy.|
2828
|getCountryLong|Return the ISO3166-1 country name of the proxy.|
29-
|getRegion|Return the ISO3166-2 region name of the proxy. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported|
29+
|getRegion|Return the ISO3166-2 region name of the proxy. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported.|
3030
|getCity|Return the city name of the proxy.|
3131
|getISP|Return the ISP name of the proxy.|
32+
|getDomain|Return the domain name of the proxy.|
33+
|getUsageType|Return the usage type classification of the proxy. Please visit <a href="https://www.ip2location.com/database/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of usage types supported.|
34+
|getASN|Return the autonomous system number of the proxy.|
35+
|getAS|Return the autonomous system name of the proxy.|
36+
|getLastSeen|Return the number of days that the proxy was last seen.|
3237

3338
## Example
3439

@@ -37,7 +42,7 @@ import IP2Proxy
3742

3843
main :: IO ()
3944
main = do
40-
let myfile = "IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.BIN"
45+
let myfile = "./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN"
4146
let ip = "199.83.103.79"
4247
meta <- open myfile
4348

@@ -52,6 +57,11 @@ main = do
5257
putStrLn $ "city: " ++ (show (city result))
5358
putStrLn $ "isp: " ++ (show (isp result))
5459
putStrLn $ "proxy_type: " ++ (show (proxy_type result))
60+
putStrLn $ "domain: " ++ (show (domain result))
61+
putStrLn $ "usage_type: " ++ (show (usage_type result))
62+
putStrLn $ "asn: " ++ (show (asn result))
63+
putStrLn $ "as: " ++ (show (as result))
64+
putStrLn $ "last_seen: " ++ (show (last_seen result))
5565
putStrLn $ "is_proxy: " ++ (show (is_proxy result))
5666

5767
result <- getCountryShort myfile meta ip
@@ -66,6 +76,16 @@ main = do
6676
putStrLn $ "isp: " ++ result
6777
result <- getProxyType myfile meta ip
6878
putStrLn $ "proxy_type: " ++ result
79+
result <- getDomain myfile meta ip
80+
putStrLn $ "domain: " ++ result
81+
result <- getUsageType myfile meta ip
82+
putStrLn $ "usage_type: " ++ result
83+
result <- getASN myfile meta ip
84+
putStrLn $ "asn: " ++ result
85+
result <- getAS myfile meta ip
86+
putStrLn $ "as: " ++ result
87+
result <- getLastSeen myfile meta ip
88+
putStrLn $ "last_seen: " ++ result
6989
result <- isProxy myfile meta ip
7090
putStrLn $ "is_proxy: " ++ result
7191
```
-96.7 KB
Binary file not shown.

dist/build/IP2Proxy.hi

-25 KB
Binary file not shown.

dist/build/IP2Proxy.o

-114 KB
Binary file not shown.

dist/build/autogen/Paths_ip2proxy.hs

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)