Logic Machine Forum
how to know current ip and gateway? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: how to know current ip and gateway? (/showthread.php?tid=5283)



how to know current ip and gateway? - gdimaria - 04.03.2024

Hi, how I can get the current gateway when LM is in DHCP?

Thanks

Peppe


RE: how to know current ip and gateway? - admin - 05.03.2024

Use this:
Code:
routes = io.readproc('route')
gateway = routes:match('default%s+([%d%.]+)')

ifinfo = require('ifinfo')()
ip = ifinfo.eth0.inetaddr

log(ip, gateway)

If DHCP is used it is highly recommended to use a static IP-MAC binding so LM IP cannot change randomly.


RE: how to know current ip and gateway? - gdimaria - 05.03.2024

(05.03.2024, 06:18)admin Wrote: Use this:
Code:
routes = io.readproc('route')
gateway = routes:match('default%s+([%d%.]+)')

ifinfo = require('ifinfo')()
ip = ifinfo.eth0.inetaddr

log(ip, gateway)

If DHCP is used it is highly recommended to use a static IP-MAC binding so LM IP cannot change randomly.

Thanks

Peppe