Created
February 11, 2024 04:11
-
-
Save vicradon/48482d1e8aea288c80f86b22e29f0db0 to your computer and use it in GitHub Desktop.
This script allows you to open a socket connection on port 80 on a unix machine. It requires elevated privileges to run.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
server_socket.bind(('localhost', 80)) | |
server_socket.listen(1) | |
print('Server listening on port 80...') | |
client_socket, client_address = server_socket.accept() | |
print('Connection from:', client_address) | |
data = client_socket.recv(1024) | |
print('Received data:', data.decode('utf-8')) | |
response = 'Hello, client! This is the server.' | |
client_socket.send(response.encode('utf-8')) | |
# server_socket.close() | |
# client_socket.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment