This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Is there any way that I can get DHCP table?
#8
(04.01.2021, 07:57)admin Wrote: You should save the device IP in storage and periodically run the scan via a scheduled scripts to check for IP changes. You should also set a lower value for socket.http.TIMEOUT because default is 60 seconds to speed up the script. Check if your device has a non-standard TCP port open so the scan more consistent, because many network devices can have port 80 open.

Here's a script that can quickly check if any of local IPs have port 80 open:
Code:
require('socket')
prefix = '192.168.1.' -- ip address prefix
rangemin, rangemax = 2, 254 -- min/max of the scan range
port = 80 -- TCP port to check

sockets = {}
ips = {}

-- create sockets and connect
for i = rangemin, rangemax do
  ip = prefix .. i
 
  sock = socket.tcp()
  sock:settimeout(0)
  sock:connect(ip, port)

  sockets[ #sockets + 1 ] = sock
  ips[ sock ] = ip
end

-- get a list of sockets that can be written to, this means that the connection is established
_, res, err = socket.select(nil, sockets, 1)

res = res or {}

-- log IPs of all sockets that accepted the connection
for _, sock in ipairs(sockets) do
  if res[ sock ] then
    ip = ips[ sock ]
    log(ip)
  end

  sock:close()
end

-- clean-up in case running as a resident script
sockets = nil
ips = nil

Is it possible to get Name and MAC adress with this script?
Reply


Messages In This Thread
RE: Is there any way that I can get DHCP table? - by victor.back - 10.01.2021, 12:16

Forum Jump: