Skip to content
Snippets Groups Projects
Commit 6fb27ad8 authored by Nicolas KAROLAK's avatar Nicolas KAROLAK
Browse files

filter nmcli output with ip pattern

parent c78db901
No related branches found
No related tags found
No related merge requests found
......@@ -18,13 +18,14 @@ from envsetup import utils as u # noqa: E402
def get_dns_servers() -> set:
servers = list()
ip_pattern = re.compile(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$")
if subprocess.getstatusoutput("command -v nmcli")[0] == 0:
# network-manager
_, output = subprocess.getstatusoutput(
"nmcli -f all device show | grep IP4.DNS | awk '{ print $2 }'"
)
servers = [l for l in output.split("\n") if l]
servers = [l for l in output.split("\n") if ip_pattern.match(l)]
if not len(servers):
# resolvconf
......@@ -38,7 +39,6 @@ def get_dns_servers() -> set:
_, output = subprocess.getstatusoutput("systemd-resolve --status")
lines = [l.strip() for l in output.split("\n")]
dns_line = False
ip_pattern = re.compile("\d+\.\d+\.\d+\.\d+")
for line in lines:
if line.startswith("DNS Servers:"):
dns_line = True
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment