Skip to content

Commit

Permalink
remove --prefer-ipv6 flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Bartosz-lab committed Oct 22, 2024
1 parent 99db061 commit 11c2d2b
Showing 1 changed file with 4 additions and 20 deletions.
24 changes: 4 additions & 20 deletions openwisp-config/files/sbin/openwisp-get-address.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
#!/usr/bin/env lua

-- gets the first useful address of the specified interface
-- fistly tries to get an IPv4 address, if not found, tries to get an IPv6 address
-- with the --prefer-ipv6 option, it will try to get an IPv6 address first
-- usage:
-- * openwisp-get-address <ifname> [--prefer-ipv6]
-- * openwisp-get-address <network-name> [--prefer-ipv6]
-- * openwisp-get-address <ifname>
-- * openwisp-get-address <network-name>
local os = require('os')
local net = require('openwisp.net')
local name = arg[1]
local prefer_ipv6 = arg[2] == "--prefer-ipv6"

local ip_version1, ip_version2

if prefer_ipv6 then
ip_version1 = 'inet6'
ip_version2 = 'inet'
else
ip_version1 = 'inet'
ip_version2 = 'inet6'
end


local interface = net.get_interface(name, ip_version1)
local interface = net.get_interface(name, 'inet')
if not interface then
interface = net.get_interface(name, ip_version2)
interface = net.get_interface(name, 'inet6')
end


if interface then
print(interface.addr)
else
Expand Down

0 comments on commit 11c2d2b

Please sign in to comment.