Exemple #1
0
 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"
Exemple #2
0
 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"
Exemple #3
0
    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()
Exemple #4
0
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"