I have a server on port 10000, and devices connect to it. How can I disable the specified device by IP address? There may be several device IP addresses on the port, and you need to disable the specified one.
I tried to do it through the socket library in Python, but it requires a connection to a port that is already occupied by the server therefore, the code below does not work for me.
def drop_connections(ip, port):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
s.close()
print(f"Connection to {ip}:{port} closed successfully.")
except Exception as e:
print(f"Error while closing connection: {e}")
EgasVegas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.