I would like to add a small section to my router's main status page, to display the WAN interface's PTR record if connected and resolvable.
Proper documentation on LuCI seems hard to come by, my understanding so far is:-
I can create a dir called "index" within "/usr/lib/lua/luci/view/admin_status/", place HTML files in there and they will be appended to the view upon access;
These HTML files can break into Lua scripting with percent tags (<% %>);
Certain LuCI libraries can be used within the scripts.
Based upon this, I would like to use the API call luci.sys.net.routes() to obtain the default IPV4 route gateway, which should be the WAN IP address. But my attempts keep failing because either the library or the function doesn't exist.
Am I looking at old API docs, or is something else wrong?
I think it would be quite helpful if you posted your current code as well
Well I managed to track down a git commit from 2017 that indicated that luci.sys.net.routes() was deprecated, so I have to use luci.ip.routes() or luci.ip.route() instead.
Of course, nothing written in the docs to suggest a problem
So, having changed the call I've since made progress, in that I get the default route and the device that it would send from (the WAN side of the router).
Now, how do I get IP addresses for a device name e.g. eth1?
src attribute of the returned route object. An interface might have multiple IPs and you usually want to utilize the one that would be used as source IP for outbound traffic.
To obtain the reverse DNS entry you can utilize
local ip = require("luci.ip")
local nx = require("nixio")
local default_route = ip.route("220.127.116.11")
if default_route and default_route.src then
local egress_ip = default_route.src:host():string()
<strong>Current PTR record:</strong>
<%= get_ptr() or "<em>unknown</em>" %>
As a command-line oneliner for testing:
lua -lluci.ip -lnixio -e 'print(nixio.getnameinfo(luci.ip.route("18.104.22.168").src:ho
Relevant API docs:
Ah. The docs for "luci.ip.route()" indicate that the "src" field is optional as a return value, so I was thrown.
Thanks, this would make a good basic tutorial.
This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.