1
This commit was merged in pull request #1.
This commit is contained in:
+12
-14
@@ -1,6 +1,5 @@
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import platform
|
||||
import re
|
||||
|
||||
host_window = r'C:\Windows\System32\drivers\etc\hosts'
|
||||
host_mac = r'/etc/hosts'
|
||||
@@ -14,23 +13,22 @@ def search_host(hostvalue):
|
||||
host_path = host_mac
|
||||
else:
|
||||
host_path = host_window
|
||||
hostfile = open(host_path, 'r', errors='ignore')
|
||||
each_line = hostfile.readlines()
|
||||
hostfile.close()
|
||||
with open(host_path, errors='ignore') as hostfile:
|
||||
each_line = hostfile.readlines()
|
||||
findresult = re.findall(hostvalue, ''.join(each_line))
|
||||
return findresult
|
||||
|
||||
|
||||
def write_host(hostvalue):
|
||||
if platform.system().lower() != 'windows':
|
||||
output = open(host_mac, 'a')
|
||||
else:
|
||||
output = open(host_window, 'a')
|
||||
|
||||
for insid in hostvalue:
|
||||
output.write(insid)
|
||||
output.write('\n')
|
||||
output.close()
|
||||
output = open(host_mac, 'a')
|
||||
else:
|
||||
output = open(host_window, 'a')
|
||||
|
||||
with output:
|
||||
for insid in hostvalue:
|
||||
output.write(insid)
|
||||
output.write('\n')
|
||||
|
||||
|
||||
def host_init():
|
||||
|
||||
Reference in New Issue
Block a user