|
|
- function M.getipinfo(_, params)
- local ip = type(params) == "table" and params.ip or nil
- if not ip then
- return nil
- end
- local cjson = require("cjson")
- local ipinfo = nil
- local cmd = string.format("curl -sk https://ip9.com.cn/get?ip=%s", ip)
- local raw = sh.read(cmd)
- if not raw or raw == "" then
- return nil
- end
- local ok, decoded = pcall(cjson.decode, raw)
- if not ok or type(decoded) ~= "table" or decoded.ret ~= 200 then
- return nil
- end
- local data = decoded.data
- if not data then
- return nil
- end
- -- 组装 info 字段,过滤空值
- local parts = {}
- if data.prov and data.prov ~= "" then table.insert(parts, data.prov) end
- if data.city and data.city ~= "" then table.insert(parts, data.city) end
- if data.isp and data.isp ~= "" then table.insert(parts, data.isp) end
- local info = table.concat(parts, " ")
- if info == "" then
- return nil
- end
- return info
- end
复制代码
|
|