Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion packages/ns-plug/files/inventory
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import re
import json
import subprocess
import ipaddress
from euci import EUci
from struct import pack
from nethsec import utils, inventory
Expand Down Expand Up @@ -71,6 +72,22 @@ def _get_gateway(interface):
except:
return ''

def _get_public_ip():
# Try ifconfig.co: sometimes the site returns an HTML error page, ignore it
address = _run("curl --fail --max-time 5 --retry 2 https://ifconfig.co")
try:
ipaddress.ip_address(address)
return address
except:
# Fallback to DNS query
address = _run("dig +short myip.opendns.com @resolver1.opendns.com")

try:
ipaddress.ip_address(address)
return address
except:
return ''

release = _run('grep VERSION= /etc/os-release | cut -d= -f 2 | tr -d \'"\'')
cpu_info = _run_json('lscpu -J')['lscpu']
binfo = _run_json("cat /etc/board.json")
Expand Down Expand Up @@ -152,7 +169,7 @@ data = {
}
},
"rpms": { "nethserver-firewall-base-ui": _run("opkg status ns-ui | grep Version | awk '{print $2}'") },
"public_ip": _run("curl https://ifconfig.co"),
"public_ip": _get_public_ip(),
"features": features
}

Expand Down
Loading