ip2proxy-resty

用于 OpenResty 的 IP2Proxy 代理检测库

$ opm get ip2location/ip2proxy-resty

IP2Proxy OpenResty 包

此包允许用户查询 IP 地址是否被用作 VPN 匿名器、开放代理、网页代理、Tor 出口、数据中心、网页托管 (DCH) 范围、搜索引擎机器人 (SES) 和住宅 (RES)。它从 **IP2Proxy BIN 数据** 文件中查找代理 IP 地址。此数据文件可以从以下位置下载

  • 免费 IP2Proxy BIN 数据:https://lite.ip2location.com

  • 商业 IP2Proxy BIN 数据:https://www.ip2location.com/database/ip2proxy

作为替代方案,此包也可以调用 IP2Proxy Web 服务。这需要一个 API 密钥。如果您没有现有的 API 密钥,可以在以下位置订阅一个

https://www.ip2location.com/web-service/ip2proxy

安装

    opm get ip2location/ip2proxy-resty

使用 BIN 文件查询

功能

以下是此包支持的功能。

|函数名称|描述| |---|---| |open|打开 IP2Proxy BIN 数据以进行查找。| |close|关闭并清理文件指针。| |get_package_version|获取包版本(PX1 到 PX11 分别为 1 到 11)。| |get_module_version|获取模块版本。| |get_database_version|获取数据库版本。| |isproxy|检查 IP 地址是否为代理。返回值:<ul><li>-1 : 错误</li><li>0 : 不是代理</li><li>1 : 代理</li><li>2 : 数据中心 IP 地址或搜索引擎机器人</li></ul>| |get_all|返回对象中的代理信息。| |get_proxytype|返回代理类型。请访问 <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> 查看支持的代理类型列表| |get_country_short|返回代理的 ISO3166-1 国家代码(2 位)。| |get_country_long|返回代理的 ISO3166-1 国家名称。| |get_region|返回代理的 ISO3166-2 地区名称。请访问 <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 分区代码</a> 获取支持的 ISO3166-2 信息| |get_city|返回代理的城市名称。| |get_isp|返回代理的 ISP 名称。| |get_domain|返回代理的域名。| |get_usagetype|返回代理的使用类型分类。请访问 <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> 查看支持的使用类型列表| |get_asn|返回代理的自治系统编号。| |get_as|返回代理的自治系统名称。| |get_lastseen|返回代理最后一次被看到的日期数。| |get_threat|返回代理的威胁类型。| |get_provider|返回代理的提供商。|

用法

    worker_processes  1;
    error_log logs/error.log;
    events {
        worker_connections 1024;
    }
    http {
        server {
            listen 8080 reuseport;
            location / {
                default_type text/html;
                content_by_lua_block {
                    ip2proxy = require('ip2proxy')
                    local ip2prox = ip2proxy:open('/usr/local/ip2location/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN')
                    local result = ip2prox:get_all('8.8.8.8')
                    ngx.say("country_short: " .. result.country_short)
                    ngx.say("country_long: " .. result.country_long)
                    ngx.say("region: " .. result.region)
                    ngx.say("city: " .. result.city)
                    ngx.say("isp: " .. result.isp)
                    ngx.say("domain: " .. result.domain)
                    ngx.say("usagetype: " .. result.usagetype)
                    ngx.say("asn: " .. result.asn)
                    ngx.say("as: " .. result.as)
                    ngx.say("lastseen: " .. result.lastseen)
                    ngx.say("threat: " .. result.threat)
                    ngx.say("provider: " .. result.provider)
                    ngx.say("proxytype: " .. result.proxytype)
                    ngx.say("isproxy: " .. result.isproxy)
                    ip2prox:close()
                }
            }
        }
    }
    

使用 IP2PROXY 代理检测 Web 服务查询

功能

以下是此包支持的功能。

|函数名称|描述| |---|---| |open|预期 3 个输入参数:<ol><li>IP2Proxy API 密钥。</li><li>包(PX1 - PX11)</li></li><li>使用 HTTPS 或 HTTP</li></ol> | |lookup|查询 IP 地址。此函数返回包含代理信息的表。 <ul><li>countryCode</li><li>countryName</li><li>regionName</li><li>cityName</li><li>isp</li><li>domain</li><li>usageType</li><li>asn</li><li>as</li><li>lastSeen</li><li>threat</li><li>proxyType</li><li>isProxy</li><li>provider</li><ul>| |get_credit|此函数返回 Web 服务信用余额表。|

用法

    worker_processes  1;
    error_log logs/error.log;
    events {
        worker_connections 1024;
    }
    http {
        resolver 8.8.8.8;
        server {
            listen 8080 reuseport;
            location / {
                default_type text/html;
                content_by_lua_block {
                    local apikey = 'YOUR_API_KEY'
                    local apipackage = 'PX11'
                    local usessl = true
                    local ip = '8.8.8.8'
                    ip2proxywebservice = require('ip2proxywebservice')
                    local ws = ip2proxywebservice:open(apikey, apipackage, usessl)
                    local result = ws:lookup(ip)
                    if result["response"] ~= nil then
                        if result.response == "OK" then
                            ngx.say("countryCode: " .. result.countryCode)
                            ngx.say("countryName: " .. result.countryName)
                            ngx.say("regionName: " .. result.regionName)
                            ngx.say("cityName: " .. result.cityName)
                            ngx.say("isp: " .. result.isp)
                            ngx.say("domain: " .. result.domain)
                            ngx.say("usageType: " .. result.usageType)
                            ngx.say("asn: " .. result.asn)
                            ngx.say("as: " .. result.as)
                            ngx.say("lastSeen: " .. result.lastSeen)
                            ngx.say("threat: " .. result.threat)
                            ngx.say("provider: " .. result.provider)
                            ngx.say("proxyType: " .. result.proxyType)
                            ngx.say("isProxy: " .. result.isProxy)
                        else
                            print("Error: " .. result.response)
                        end
                    end
                    local result2 = ws:get_credit()
                    if result2["response"] ~= nil then
                        ngx.say("Credit Balance: " .. result2.response)
                    end
                }
            }
        }
    }

作者

IP2Location.com

许可证

mit

依赖项

版本