That works well if the machine has a single network interface configured; just note that difficulties may arise if more than one adapter is (or has been) present. For example, one windows box that used to have a physical cable connection returns the ip for that nic even though the only valid network is now a wifi usb adapter. And my virtual box based linux test system returns the (debian style) loopback ip of 127.0.1.1 and not the adapter address set by dhcp.
Getting local IP address using UDP?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Getting local IP address using UDP?
Re: Getting local IP address using UDP?
Note that this will only work on an English installation of Windows as these texts are translated.yal2du wrote: ↑Fri Apr 22, 2022 7:29 pmCode: Select all
local s_dg = " Default Gateway . . . . . . . . . :" local s_ip = " IPv4 Address. . . . . . . . . . . : "
Tools: Hot Particles, LuaPreprocess, InputField, (more) Games: Momento Temporis
"If each mistake being made is a new one, then progress is being made."
"If each mistake being made is a new one, then progress is being made."
Re: Getting local IP address using UDP?
System locale could be an issue with any os and non-ascii encoding formats could be a problem as well (lua 5.1 string library doesn't handle anything beyond 8-bit clean). What I posted was just an approach to importing the output of a shell command, and parsing the same (mainly to illustrate that it is possible to do so without having to write/read to/from a temporary file). A temp file approach (using os.execute and possibly os.tempname) can be cumbersome if one must poll to check if/when a file has been modified).
Ideally, using the luajit.ffi one could make the appropriate system call and grab all the current legit ip addresses and avoid all of this 'hackiness'.
Hackiness - “Hacky” problem-solving behavior. We construe hacky problem-solving behavior as a two-facet construct that relates to the extent to which one invests cognitive resources in order to avoid tedious/brute-force problem-solving strategies in favor of clever/finessed problem-solving strategies. The first facet of the construct is intolerance of tedium, and refers to the threshold of tedium at which one chooses to seek a hacky solution to a problem. The second facet of the construct is tenacity, and refers to the amount of time and effort one will expend in order to find a hacky solution before one “gives up” and defers to a brute-force solution. ~ Zack Tidler
Who is online
Users browsing this forum: Bing [Bot], Google [Bot], rabbitboots and 12 guests