成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專欄INFORMATION COLUMN

openResty IP數(shù)據(jù)庫

nodejh / 2587人閱讀

摘要:數(shù)據(jù)庫數(shù)據(jù)庫之版,為了方便使用數(shù)據(jù)所封裝的拓展包。使用方式本腳本封裝了的主要接口配制好后就可以直接使用,并不需要再去復雜的內(nèi)部實現(xiàn)。同樣希望這個腳本能提供給官方推薦腳本。

openResty IP數(shù)據(jù)庫

ipip.net IP數(shù)據(jù)庫之openresty版,為了方便nginx使用ip 數(shù)據(jù)所封裝的拓展包。

使用方式

本腳本封裝了ipip.net的主要接口配制好后就可以直接使用,并不需要再去復雜的內(nèi)部實現(xiàn)。

需要注意的是如果使用api訪問需要http拓展包。

代碼我已提交至GitHub: https://github.com/icowan/lua-resty-17mon

如果對lua不了解請看我前段時間寫的: 《Lua基礎學習方式 (一天學會) 》

如果還沒安裝openresty請看: 《優(yōu)雅的安裝openresty 》

`

nginx 配制

要使用首先得載入自己寫義的lualib,這個根據(jù)你安裝的或使用方式去修改路徑。

lua_package_path "/usr/local/openresty/lualib/?.lua;/var/www/lua-resty-17mon/lualib/?.lua;;";
lua_package_cpath "/usr/local/openresty/lualib/?.so;;";

error_log /var/www/lua-resty-17mon/logs/lua-resty-17mon.debug.log debug;

server {
    listen 8080;
    server_name localhost;
    charset utf-8;
    location /ipLocation {
        resolver 8.8.8.8; # 如果要使用api的話 需要dns 這可以改成中國的會快一些
        default_type "text/plain";
        content_by_lua_file "/var/www/lua-resty-17mon/script/ip_location.lua";
    }
}
lua 腳本使用
-- /var/www/lua-resty-17mon/script/ip_location.lua

ngx.req.read_body()
ngx.header.content_type = "application/json;charset=UTF-8"

local cjson = require "cjson"

local success = function(con)
    return cjson.encode({
        success = true,
        body = con
    })
end

local failure = function(err)
    return cjson.encode({
        success = false,
        errors = err
    })
end

-- 參數(shù)獲取
local request_args = ngx.req.get_uri_args()
local ip_address = request_args["ip"]

-- 如果不需要驗證可以不用此拓展
local checkIp = require("ip_check"):new(ip_address)

-- 驗證ip
local ok, err = checkIp:checkIp()
if not ok then
    ngx.say(failure(err))
    return
end

-- 使用本地數(shù)據(jù)庫
local ipdetail, err = require("ip_location"):new(ip_address, "/var/www/lua-resty-17mon/file/17monipdb.dat")
if not ipdetail then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

local ipLocation, err = ipdetail:location()
if not ipLocation then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

ngx.say(success(ipLocation))
通過免費api獲取ip信息

如果通過api獲取數(shù)據(jù)需要使用http服務,這里需要使用lua-resty-http
這里我已經(jīng)把它直接放到lualib/resty目錄了,可以直接使用 感謝pintsized提供的腳本

-- /var/www/lua-resty-17mon/script/ip_location.lua

local ipdetail, err = require("ip_location"):new(ip_address)
if not ipdetail then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

local ipLocation, err = ipdetail:locationApiFree()
if not ipLocation then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

ngx.say(success(ipLocation))
通過付費api獲取ip信息
-- /var/www/lua-resty-17mon/script/ip_location.lua

local ipdetail, err = require("ip_location"):new(ip_address, "", "your token")
if not ipdetail then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

local ipLocation, err = ipdetail:locationApiFree()
if not ipLocation then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

ngx.say(success(ipLocation))
獲取aip使用狀態(tài)
-- /var/www/lua-resty-17mon/script/ip_location.lua

local ipdetail, err = require("ip_location"):new(ip_address, "your token")
if not ipdetail then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

local ipLocation, err = ipdetail:apiStatus()
if not ipLocation then
    ngx.log(ngx.ERR, err)
    ngx.say(failure(err))
    return
end

ngx.say(success(ipLocation))
返回數(shù)據(jù)結構

Response

返回類型: JSON

參數(shù) 類型 備注
success bool true or false
errors or body string 當success為false時errors有值否則返回body

body返回參數(shù)詳情

參數(shù) 類型 備注
country string 國家
city string 省會或直轄市(國內(nèi))
region string 地區(qū)或城市 (國內(nèi))
place string 學校或單位 (國內(nèi))
operator string 運營商字段
latitude string 緯度
longitude string 經(jīng)度
timeZone string 時區(qū)一, 可能不存在
timeZoneCode string 時區(qū)碼
administrativeAreaCode string 中國行政區(qū)劃代碼
internationalPhoneCode string 國際電話代碼
countryTwoDigitCode string 國家二位代碼
worldContinentCode string 世界大洲代碼

返回結果參考:

{
    "success": true,
    "body": {
        "country": "",  // 國家
        "city": "",  // 省會或直轄市(國內(nèi))
        "region": "",  // 地區(qū)或城市 (國內(nèi))
        "place": "",  // 學?;騿挝?(國內(nèi))
        "operator": "",  // 運營商字段(只有購買了帶有運營商版本的數(shù)據(jù)庫才會有)
        "latitude": "",  // 緯度     (每日版本提供)
        "longitude": "",  // 經(jīng)度     (每日版本提供)
        "timeZone": "",  // 時區(qū)一, 可能不存在  (每日版本提供)
        "timeZoneCode": "",  // 時區(qū)碼, 可能不存在  (每日版本提供)
        "administrativeAreaCode": "",  // 中國行政區(qū)劃代碼    (每日版本提供)
        "internationalPhoneCode": "",  // 國際電話代碼        (每日版本提供)
        "countryTwoDigitCode": "",  // 國家二位代碼        (每日版本提供)
        "worldContinentCode": ""  // 世界大洲代碼        (每日版本提供)
    }
}

ERROR結果參考

{
    "success": false,
    "erros": "retun messages..."
}

查詢狀態(tài)結果參考

{
    "success": true,
    "body": {
        "limit": false, // 是否已受訪問限制
       "hour": 99680,  // 一個小時內(nèi)剩余次數(shù)
       "day": 999680,  // 24小時內(nèi)剩余次數(shù)
    }
}
尾巴

難得為開源社區(qū)貢獻一份力量,希望有同樣需求的同學們可以不用再去寫復雜的底層邏輯,應該更多的把時間估計業(yè)務流程上。

同樣希望這個腳本能提供給ipip.net官方推薦腳本。

或訪問我 網(wǎng)站: LatteCake

本文地址: http://lattecake.com/post/20102

文章版權歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/39376.html

相關文章

  • (學習到實踐)七、mongodb測試,php+nginx負載均衡的部署

    摘要:運行容器意外的官方參考地址,多次嘗試命令最終無法運行,帶項時后是狀態(tài),修改配置沒反應日志無報錯退出。目前容器整體情況是主從,個相同一個。后續(xù)運行的容器數(shù)視情況而定。接下來計劃針對,一些實際應用場景進行實踐驗證。 目標需求: 密碼登錄+容器數(shù)據(jù)共享,主從復制 1.配置啟動 添加配置文件夾,組織容器命令。 a.官方未提供相關信息 從測試容器中匹配搜索得到 mongod.conf.orig,...

    fyber 評論0 收藏0
  • Mac下使用ABTestingGateway快速搭建灰度網(wǎng)關

    摘要:下使用快速搭建灰度網(wǎng)關簡介是新浪開源的一個可以動態(tài)設置分流策略的灰度發(fā)布系統(tǒng),工作在層,基于和開發(fā),使用作為分流策略數(shù)據(jù)庫,可以實現(xiàn)動態(tài)調(diào)度功能。目前在京東如實時價格秒殺動態(tài)服務單品頁列表頁等都在使用架構,其他公司如淘寶去哪兒網(wǎng)等。 Mac下使用ABTestingGateway快速搭建灰度網(wǎng)關 ABTestingGateway簡介 ABTestingGateway 是新浪開源的一個可以...

    2bdenny 評論0 收藏0
  • 如何在云幫上配置https

    摘要:云幫所有的對外服務都配置在負載均衡上,都是通過負載均衡轉(zhuǎn)發(fā)到對應的應用與服務。大概的操作流程如下那么接下來就說說如何具體去配置。測試即可,如果多節(jié)點配置直接配置就了。配置到這里,云幫已經(jīng)配置完成了。 序 相關組件介紹 本次分享主要涉及到兩個模塊console模塊和openresty模塊。 console模塊 即云幫(ACP)控制臺模塊,為用戶提供可視化Web操作界面,監(jiān)聽443端口即可...

    馬龍駒 評論0 收藏0
  • OpenrestyOpenresty增加waf配置

    摘要:說明防止注入,本地包含,部分溢出,測試,等攻擊防止備份之類文件泄漏防止之類壓力測試工具的攻擊屏蔽常見的掃描黑客工具,掃描器屏蔽異常的網(wǎng)絡請求屏蔽圖片附件類目錄執(zhí)行權限防止上傳下載使用使用安裝下載解壓后,將整放到目錄中,并命名為配置安裝路徑假 1. Ngx lua waf 說明 防止sql注入,本地包含,部分溢出,fuzzing測試,xss,SSRF等web攻擊防止svn/備份之類文件泄...

    iliyaku 評論0 收藏0

發(fā)表評論

0條評論

最新活動
閱讀需要支付1元查看
<