Skip to content

Instantly share code, notes, and snippets.

@T0biii
Last active March 26, 2024 19:40
Show Gist options
  • Save T0biii/a5171e0f9ce584851490bd6255ecd341 to your computer and use it in GitHub Desktop.
Save T0biii/a5171e0f9ce584851490bd6255ecd341 to your computer and use it in GitHub Desktop.
checkuplink and parse-wgkex-response.lua
local json = require 'jsonc'
local input = assert(arg[1])
local data = assert(json.parse(input))
-- v1
if data.Message == "OK" then
return
end
-- v2
if not data.Endpoint or not data.Endpoint.Address or not data.Endpoint.Port
or not data.Endpoint.PublicKey or not data.Endpoint.AllowedIPs or not data.Endpoint.AllowedIPs[1] then
error("Malformed JSON response, missing required value")
end
print(data.Endpoint.Address)
print(data.Endpoint.Port)
print(data.Endpoint.PublicKey)
print(data.Endpoint.AllowedIPs[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment