Obtain client IP using JS/Lua

Hi Everyone,

Is it possible to determine the IP address (MAC would be better, but from research, I understand this isn't possible) of a client that is connecting the Luci interface? I have tried using getpeername/getpeer in a Lua script, but to no avail.

Cheers

Tim

AFAIK, you can get the client's IP from the uhttpd environment variables and then can parse DHCP leases file to obtain mac address.

1 Like

Any idea how I can go about accessing these variables - I've had a quick google and the closest I've got is nixio.getenv(), but that doesn't give me what I need using:

for k,v in pairs(nixio.getenv()) do
  print(k, v)
end

Cheers

Tim

Got it!

require "luci.http"
...
print(luci.http.getenv('REMOTE_ADDR'))

Thanks!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.