def modify(self, dns): LinuxDNSCfg.modify(self, dns) services = self.getallnetworkservices() for service in services: self.setdnsservers(service, [dns]) ''' try: subprocess.check_output(["killall", "-HUP", "mDNSResponder"]) except: pass ''' print ">> Darwin modified"
def restore(self): LinuxDNSCfg.restore(self) backupfile = None backupfilelocation = "/etc/puredns_darwin.conf" try: backupfile = open(backupfilelocation, "r") backup = backupfile.read() conf = json.loads(backup) for key in conf: self.setdnsservers(key, conf[key]) finally: if backupfile: backupfile.close() os.remove(backupfilelocation) print ">> Darwin restored"
def backup(self): ''' Didn't consider the case when some other force remove the backupfile ''' LinuxDNSCfg.backup(self) backupfile = None if 'puredns_darwin.conf' in os.listdir("/etc"): return try: backupfile = open('/etc/puredns_darwin.conf', 'w+') conf = {} services = self.getallnetworkservices() for service in services: servers = self.getdnsservers(service) conf[service] = servers jsonconf = json.dumps(conf) backupfile.write(jsonconf) except Exception as e: print e finally: if backupfile: backupfile.close()
def create_dnscfg(): s = platform.system() if s == "Darwin": from dnscfg.darwin_dnscfg import DarwinDNSCfg return DarwinDNSCfg() elif s == "Linux": from dnscfg.linux_dnscfg import LinuxDNSCfg return LinuxDNSCfg() elif s == "Windows": try: from dnscfg.windows_dnscfg import WindowsDNSCfg return WindowsDNSCfg() except: print 'wmi method not working try netsh' from dnscfg.windows_netsh_dnscfg import WindowsNetshDNSCfg return WindowsNetshDNSCfg() else: print "Unsuppoerted os"