diff options
Diffstat (limited to 'helpers.py')
-rw-r--r-- | helpers.py | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -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' + + |