'how can i create a local dns in python
i wrote a script getting my ip address and connecting it to a file. what i want is to change the ip address to a dns which i can access on both my laptop and other devices that are connected to the same wifi or router.
from fileinput import filename
from importlib.resources import contents
import socket
from urllib import response
PORT = 5050
IP = socket.gethostbyname(socket.gethostname())
print(IP)
ADDR = (IP, PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((IP, PORT))
s.listen(5)
while True:
clientSocket, address = s.accept()
print(f'Connection established from address {address}')
req = clientSocket.recv(1024)
filename = 'hello.html'
f = open(filename, 'r')
content = f.read()
f.close()
response = 'HTTP/1.0 200 OK\n\n' + content
clientSocket.sendall(response.encode())
clientSocket.close()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
