Files
dotfiles/bin/test_ip.lua
Archie Fox 06b8ee8caf Init commit
2025-06-08 06:59:19 +03:00

37 lines
727 B
Lua
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env lua
local http = require("socket.http")
local ltn12 = require("ltn12")
-- Функция для получения внешнего IP-адреса
function get_external_ip()
local services = {
"https://api.ipify.org",
"https://ident.me",
"https://ifconfig.me/ip",
}
for _, url in ipairs(services) do
local response = {}
local _, status = http.request({
url = url,
sink = ltn12.sink.table(response),
})
if status == 200 then
return table.concat(response)
end
end
return nil, "Не удалось получить IP-адрес"
end
-- Основная часть скрипта
local ip, err = get_external_ip()
if ip then
print(ip)
else
print("Ошибка: " .. err)
end