diff --git a/run.py b/run.py index 07bb3b3..7fb2234 100644 --- a/run.py +++ b/run.py @@ -182,7 +182,7 @@ def revert(self, event): def modifyhosts(extra, undo): - nullip = "0.0.0.0 " # IP to route domains to + nullip = "127.0.0.0 " # IP to route domains to # List of tracking domains normallist = ['a-0001.a-msedge.net', 'a-0002.a-msedge.net', 'a-0003.a-msedge.net', @@ -227,16 +227,23 @@ def modifyhosts(extra, undo): hostspath = os.path.join(os.environ['SYSTEMROOT'], 'System32\\drivers\\etc\\hosts') if not undo: - try: - with open(hostspath, 'ab') as f: - f.write('\r\n' + '\r\n'.join(normallistip)) - if extra: + if not extra: + try: + with open(hostspath, 'ab') as f: + f.write('\r\n' + '\r\n'.join(normallistip)) + print "Domains successfully appended to HOSTS file." + except (WindowsError, IOError): + print "Could not access HOSTS file. Is the program not elevated?" + + elif extra: + try: + with open(hostspath, 'ab') as f: f.write('\r\n' + '\r\n'.join(extralistip)) - print "Domains successfully appended to HOSTS file." - except (WindowsError, IOError): - print "Could not access HOSTS file. Is the program not elevated?" + print "Extra domains successfully appended to HOSTS file." + except (WindowsError, IOError): + print "Could not access HOSTS file. Is the program not elevated?" - else: + elif undo: try: with open(hostspath, 'r') as hostfile, open(hostspath + "temp", 'w') as tempfile: for line in hostfile: