Get LUA IP address

Asked

Viewed 232 times

5

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

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

How can I get the IP from another wifi interface? it is possible to choose the interface?

2 answers

1

I don’t know if the library socket allows this.

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

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

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

1

IFCONFIG ON LINUX

If you want to know how to use the IP by ifconfig just do this in the note block:

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 ()())

Browser other questions tagged

You are not signed in. Login or sign up in order to post.