Skip to content
This repository has been archived by the owner on Jan 4, 2022. It is now read-only.

Commit

Permalink
Change hosts permission to writeable
Browse files Browse the repository at this point in the history
  • Loading branch information
derekhe committed Nov 16, 2021
1 parent 7308ea7 commit f4f8392
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import dns
import os
import stat
import subprocess
import dns.resolver
import traceback
Expand Down Expand Up @@ -35,16 +37,20 @@ def get_hosts_origin_ips():

def override_hosts():
print("Overriding hosts")
os.chmod(host_path, stat.S_IWRITE)
with open(host_path, "a") as f:
f.writelines(host_entries)
print("Hosts override")


def restore_hosts():
print("Restoring hosts")
os.chmod(host_path, stat.S_IWRITE)
with open(host_path, "r+") as f:
host = f.read()
for line in host_entries:
host = host.replace(line, "")
f.seek(0)
f.write(host)
f.truncate()
print("Restored hosts")

0 comments on commit f4f8392

Please sign in to comment.