[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaSocket: trouble getting system ip addresses
- From: Thijs Schreijer <thijs@...>
- Date: Sat, 25 May 2013 20:51:30 +0000
I'm having trouble getting the systems IP addresses.
On Windows this works;
socket.dns.toip(socket.dns.gethostname())
On Linux (raspberry pi, Ubuntu 10) it doesn't
Test code:
local socket = require("socket")
function one(name)
print('=========='..name..'===========')
local ip, v = socket.dns.toip(name)
print('name',v.name,ip)
print('alias')
for k,v in pairs(v.alias) do
print('',k,v)
end
print('address')
for k,v in pairs(v.ip) do
print('',k,v)
end
print('====================================')
end
one('localhost')
one(socket.dns.gethostname())
It delivers:
pi@raspberrypi ~ $ lua listaddr.lua
==========localhost===========
name localhost 127.0.0.1
alias
1 ip6-localhost
2 ip6-loopback
address
1 127.0.0.1
2 127.0.0.1
====================================
==========raspberrypi===========
name raspberrypi 127.0.1.1
alias
address
1 127.0.1.1
====================================
pi@raspberrypi ~ $
Where ifconfig gives me:
pi@raspberrypi ~ $ sudo ifconfig
eth0 Link encap:Ethernet HWaddr b8:27:eb:d3:67:dd
inet addr:192.168.50.5 Bcast:192.168.50.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:97124 errors:0 dropped:0 overruns:0 frame:0
TX packets:29418 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:8325137 (7.9 MiB) TX bytes:8547972 (8.1 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:72 errors:0 dropped:0 overruns:0 frame:0
TX packets:72 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:24890 (24.3 KiB) TX bytes:24890 (24.3 KiB)
pi@raspberrypi ~ $
The testcode delivers '127.0.1.1' when getting the ip for the hostname. This comes from the /etc/hosts file. Yet ifconfig clearly shows '192.168.50.5' (on eth0).
How would I get a proper list of addresses the current system uses?
Any help is greatly appreciated.
Thijs