hosts changed
This commit is contained in:
17
server.py
17
server.py
@@ -306,6 +306,21 @@ def wifi():
|
||||
# resstart netoworking
|
||||
os.system('wpa_cli -i wlan0 reconfigure')
|
||||
return index()
|
||||
|
||||
def edit_hosts(hostname):
|
||||
current_hosts = open('/etc/hosts')
|
||||
|
||||
hosts_lines = current_hosts.readlines()
|
||||
print(hosts_lines[5])
|
||||
|
||||
hosts_lines[5] = '127.0.1.1 {}'.format(hostname)
|
||||
|
||||
current_hosts.close()
|
||||
|
||||
hosts_string = ''.join(hosts_lines)
|
||||
|
||||
current_hosts = open('/etc/hosts', 'w+')
|
||||
current_hosts.write(hosts_string)
|
||||
|
||||
@app.route("/hostname", methods = ['PUT', 'POST', 'GET'])
|
||||
def hostname():
|
||||
@@ -313,6 +328,8 @@ def hostname():
|
||||
settings = json.loads(data)
|
||||
hostname = settings['hostname']
|
||||
print('hostname', hostname)
|
||||
|
||||
edit_hosts(hostname)
|
||||
os.system("sudo hostnamectl set-hostname {}".format(hostname))
|
||||
os.system("sudo systemctl restart avahi-daemon")
|
||||
|
||||
|
Reference in New Issue
Block a user