From: itachi46 Date: Fri, 18 Mar 2016 07:08:45 +0000 (+1100) Subject: Added dnsmasq and better messaging X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=408069da793922d7d650493d50bbb480d84bbe53;p=stevenblack-hosts.git Added dnsmasq and better messaging * Added restarting dnsmasq as a way to flush DNS cache * Added success messages to services being restarted * Added an error message if none of the conditions were met instead of silently failing I did not really touch OSX side of the things as I am not sure what the command does and I do not have access to an OSX box. --- diff --git a/updateHostsFile.py b/updateHostsFile.py index dda1b51d0..d6e604726 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -407,24 +407,43 @@ def updateReadme(numberOfRules): def moveHostsFileIntoPlace(finalFile): if os.name == 'posix': + dnsFlushOccured = False print ("Moving the file requires administrative privileges. " + "You might need to enter your password.") if subprocess.call(["/usr/bin/sudo", "cp", os.path.abspath(finalFile.name), "/etc/hosts"]): printFailure("Moving the file failed.") print ("Flushing the DNS Cache to utilize new hosts file...") if platform.system() == 'Darwin': + dnsFlushOccured = True if subprocess.call(["/usr/bin/sudo", "killall", "-HUP", "mDNSResponder"]): printFailure("Flushing the DNS Cache failed.") else: if os.path.isfile("/etc/rc.d/init.d/nscd"): + dnsFlushOccured = True if subprocess.call(["/usr/bin/sudo", "/etc/rc.d/init.d/nscd", "restart"]): printFailure("Flushing the DNS Cache failed.") + else: + printSuccess("Flushing DNS by restarting nscd succeeded") if os.path.isfile("/usr/lib/systemd/system/NetworkManager.service"): + dnsFlushOccured = True if subprocess.call(["/usr/bin/sudo", "/usr/bin/systemctl", "restart", "NetworkManager.service"]): printFailure("Flushing the DNS Cache failed.") + else: + printSuccess("Flushing DNS by restarting NetworkManager succeeded") if os.path.isfile("/usr/lib/systemd/system/wicd.service"): + dnsFlushOccured = True if subprocess.call(["/usr/bin/sudo", "/usr/bin/systemctl", "restart", "wicd.service"]): printFailure("Flushing the DNS Cache failed.") + else: + printSuccess("Flushing DNS by restarting wicd succeeded") + if os.path.isfile("/usr/lib/systemd/system/dnsmasq.service"): + dnsFlushOccured = True + if subprocess.call(["/usr/bin/sudo", "/usr/bin/systemctl", "restart", "dnsmasq.service"]): + printFailure("Flushing the DNS Cache failed.") + else: + printSuccess("Flushing DNS by restarting dnsmasq succeeded") + if not dnsFlushOccured: + printFailure("Unable to determine DNS management tool.") elif os.name == 'nt': print ("Automatically moving the hosts file in place is not yet supported.") print ("Please move the generated file to %SystemRoot%\system32\drivers\etc\hosts")