WIP: add ipv6

This commit is contained in:
Jannik Beyerstedt 2023-04-17 22:02:35 +02:00
parent 16e0fd5a07
commit aee9a9d352
2 changed files with 39 additions and 7 deletions

View file

@ -22,8 +22,10 @@ font = resource.load_font("vera.ttf")
local v = {
network = "<unkown>",
ethip = "<unkown>",
wlanip = "<unkown>",
ethipv4 = "<unkown>",
ethipv6 = "<unkown>",
wlanipv4 = "<unkown>",
wlanipv6 = "<unkown>",
gw = "<unkown>"
}
@ -80,9 +82,13 @@ function node.render()
-- right side: IP addresses
y = y_start
font:write(x_right, y, "Eth: " .. v.ethip, fontsize, 1,1,1,1)
font:write(x_right, y, "Eth: " .. v.ethipv4, fontsize, 1,1,1,1)
y = y + offset
font:write(x_right, y, "WiFi: " .. v.wlanip, fontsize, 1,1,1,1)
font:write(x_right, y, v.ethipv6, fontsize, 1,1,1,1)
y = y + offset
font:write(x_right, y, "WiFi: " .. v.wlanipv4, fontsize, 1,1,1,1)
y = y + offset
font:write(x_right, y, v.wlanipv6, fontsize, 1,1,1,1)
end

30
service
View file

@ -60,6 +60,30 @@ def get_ipv4(ifname):
return None
def get_ipv6(ifname):
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
return "test"
info = fcntl.ioctl(s.fileno(), 0x8915,
struct.pack('256s', ifname[:15]))
return info
# ip = socket.inet_ntoa(info[20:24])
# mask = struct.unpack('>I', fcntl.ioctl(
# s.fileno(), 0x891b, struct.pack('256s', ifname))[20:24])[0]
# # Remember: not everything has to be performance optimal :-)
# mask = bin(mask)[2:].count('1')
# return "%s/%d" % (ip, mask)
# ipv6 = socket.getaddrinfo(
# socket.gethostname(), None, socket.AF_INET6)[1][4][0]
# return "%s" & ipv6
except IOError:
return "<no ipv6>"
except:
return None
def check_network():
return os.path.exists('/sd/config/network') and "static" or "dhcp"
@ -80,8 +104,10 @@ def check_internet():
tests = [
(1, "ethip", partial(get_ipv4, "eth0")),
(1, "wlanip", partial(get_ipv4, "wlan0")),
(1, "ethipv4", partial(get_ipv4, "eth0")),
(1, "ethipv6", partial(get_ipv6, "eth0")),
(1, "wlanipv4", partial(get_ipv4, "wlan0")),
(1, "wlanipv6", partial(get_ipv6, "wlan0")),
(1, "gw", get_default_gateway),
(10, "online", check_internet),
(5, "network", check_network),