使用Haskell查询IP2Location LITE二进制数据库?

时间:2015-05-15 03:27:04

标签: haskell binary

我想使用Haskell从here查询IP2Location LITE二进制数据库。所以我想知道是否有任何现有的模块或代码来读取数据库?

2 个答案:

答案 0 :(得分:1)

我不了解ip2location,但有geoip2本机模块可以与Geoip2数据库一起使用。根据您想要使用它的内容,它可能适合您。

答案 1 :(得分:1)

您可以使用Github中的以下示例代码:

import IP2Location

main :: IO ()
main = do
    let myfile = "IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN"
    meta <- doInit myfile
    result <- doQuery myfile meta "8.8.8.8"
    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 $ "latitude: " ++ (show (latitude result))
    putStrLn $ "longitude: " ++ (show (longitude result))
    putStrLn $ "domain: " ++ (show (domain result))
    putStrLn $ "zipcode: " ++ (show (zipcode result))
    putStrLn $ "timezone: " ++ (show (timezone result))
    putStrLn $ "netspeed: " ++ (show (netspeed result))
    putStrLn $ "iddcode: " ++ (show (iddcode result))
    putStrLn $ "areacode: " ++ (show (areacode result))
    putStrLn $ "weatherstationcode: " ++ (show (weatherstationcode result))
    putStrLn $ "weatherstationname: " ++ (show (weatherstationname result))
    putStrLn $ "mcc: " ++ (show (mcc result))
    putStrLn $ "mnc: " ++ (show (mnc result))
    putStrLn $ "mobilebrand: " ++ (show (mobilebrand result))
    putStrLn $ "elevation: " ++ (show (elevation result))
    putStrLn $ "usagetype: " ++ (show (usagetype result))

您需要使用cabal安装IP2Location包:

cabal install IP2Location

黑客攻击页面:https://hackage.haskell.org/package/ip2location-8.0.4/docs/IP2Location.html