summaryrefslogtreecommitdiffstats
path: root/helpers.py
diff options
context:
space:
mode:
Diffstat (limited to 'helpers.py')
-rw-r--r--helpers.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/helpers.py b/helpers.py
index 18871a2..d8d7e85 100644
--- a/helpers.py
+++ b/helpers.py
@@ -35,3 +35,26 @@ def list_contains_any(l, sub):
if i in l:
return True
return False
+
+
+def resolvconf_nameservers():
+ l = []
+ for line in open('/etc/resolv.conf'):
+ words = line.lower().split()
+ if len(words) >= 2 and words[0] == 'nameserver':
+ l.append(words[1])
+ return l
+
+
+def resolvconf_random_nameserver():
+ l = resolvconf_nameservers()
+ if l:
+ if len(l) > 1:
+ # don't import this unless we really need it
+ import random
+ random.shuffle(l)
+ return l[0]
+ else:
+ return '127.0.0.1'
+
+