aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/ip.lua
blob: 57cb0f5e3b045cea111f2c8e074797a7c09c2ab9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local milla = require("milla")
local os = require("os")
local json = require("json")

os.setenv("ALL_PROXY", "socks5://172.17.0.1:9057")

local http = require("http")

local function get_ip(arg)
    local ip = arg
    local response, err = http.request("GET",
                                       "https://getip-api.com/json?" .. ip)
    local json_response, err = json.decode(response.body)

    local result = ""
    for key, value in ipairs(json_response) do
        result = result .. key .. ": " .. value .. "\n"
    end

    return result
end

milla.register_cmd("ip", "get_ip")