Get IP address LUA

5

I want to get the IP address through the LUA code. I have an example code that works but I get the IP of the LAN interface.

local hote, _ = socket.dns.toip(socket.dns.gethostname())

How can I get the IP from another Wi-Fi interface? is it possible to choose the interface?

    
asked by anonymous 29.06.2015 / 14:59

2 answers

1

I do not know if the socket library allows this.

An alternative is to read the report from ifconfig with io.popen("ifconfig"):read"*a" .

If you know the interface name, then you can use this name in the ifconfig call.

Unfortunately, the report format for ifconfig seems to depend on the platform: they are different on Linux and Mac OS X.

    
29.06.2015 / 18:51
1

IFCONFIG NO LINUX

If you want to know how to use IP from ifconfig just do this in the notepad:

print (io.popen ("LANG=C /sbin/ifconfig eth0"):lines ()())



print (io.popen ("LANG=C /sbin/ifconfig wlan0"):lines ()())

After saving with the name "MOSTRA_MEU_IP.txt", type this:

 ┌─[root@parrot] #lua MOSTRA_MEU_IP.txt                                    
eth0      Link encap:Ethernet  HWaddr 00:22:64:e0:d4:d4

wlan0     Link encap:Ethernet  Endereço de HW 78:44:76:9a:a0:47  

lo        Link encap:Local Loopback            

DIR or LS

print (io.popen ("LANG=C /bin/ls"):lines ()())
    
06.08.2017 / 19:08