Quickstart#

Dependencies#

This library requires IP2Proxy BIN database to function. You may download the BIN database at

Installation#

To install this module type the following:

cabal install IP2Proxy

Sample Codes#

Query geolocation information from BIN database#

You can query the geolocation information from the IP2Proxy BIN database as below:

import IP2Proxy
import qualified Data.ByteString.Lazy as BS

main :: IO ()
main = do
    let myfile = "./IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER-FRAUDSCORE.BIN"
    let ip = "197.85.191.64"
    contents <- BS.readFile myfile -- load BIN once
    meta <- openBS contents
    
    putStrLn $ "module_version: " ++ getModuleVersion
    putStrLn $ "package_version: " ++ (getPackageVersion meta)
    putStrLn $ "database_version: " ++ (getDatabaseVersion meta)
    
    result <- getAllBS contents meta ip
    putStrLn $ "country_short: " ++ (show (country_short result))
    putStrLn $ "country_long: " ++ (show (country_long result))
    putStrLn $ "region: " ++ (show (region result))
    putStrLn $ "city: " ++ (show (city result))
    putStrLn $ "isp: " ++ (show (isp result))
    putStrLn $ "proxy_type: " ++ (show (proxy_type result))
    putStrLn $ "domain: " ++ (show (domain result))
    putStrLn $ "usage_type: " ++ (show (usage_type result))
    putStrLn $ "asn: " ++ (show (asn result))
    putStrLn $ "as: " ++ (show (as result))
    putStrLn $ "last_seen: " ++ (show (last_seen result))
    putStrLn $ "threat: " ++ (show (threat result))
    putStrLn $ "provider: " ++ (show (provider result))
    putStrLn $ "fraud_score: " ++ (show (fraud_score result))
    putStrLn $ "is_proxy: " ++ (show (is_proxy result))

    result <- getCountryShortBS contents meta ip
    putStrLn $ "country_short: " ++ result
    result <- getCountryLongBS contents meta ip
    putStrLn $ "country_long: " ++ result
    result <- getRegionBS contents meta ip
    putStrLn $ "region: " ++ result
    result <- getCityBS contents meta ip
    putStrLn $ "city: " ++ result
    result <- getISPBS contents meta ip
    putStrLn $ "isp: " ++ result
    result <- getProxyTypeBS contents meta ip
    putStrLn $ "proxy_type: " ++ result
    result <- getDomainBS contents meta ip
    putStrLn $ "domain: " ++ result
    result <- getUsageTypeBS contents meta ip
    putStrLn $ "usage_type: " ++ result
    result <- getASNBS contents meta ip
    putStrLn $ "asn: " ++ result
    result <- getASBS contents meta ip
    putStrLn $ "as: " ++ result
    result <- getLastSeenBS contents meta ip
    putStrLn $ "last_seen: " ++ result
    result <- getThreatBS contents meta ip
    putStrLn $ "threat: " ++ result
    result <- getProviderBS contents meta ip
    putStrLn $ "provider: " ++ result
    result <- getFraudScoreBS contents meta ip
    putStrLn $ "fraud_score: " ++ result
    result <- isProxyBS contents meta ip
    putStrLn $ "is_proxy: " ++ result