Last active
July 15, 2022 17:36
-
-
Save raresteak/ab9184f6e7c98ad7de5d6508672a807c to your computer and use it in GitHub Desktop.
TCP Port listener using Python
This file contains hidden or 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
#!/usr/bin/env python3 | |
import socket | |
import datetime | |
import time | |
HOST = '0.0.0.0' | |
PORT = 8080 | |
def listener(): | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.bind((HOST, PORT)) | |
s.listen() | |
conn, addr = s.accept() | |
with conn: | |
dateTime = datetime.datetime.now() | |
print('Connected by', addr , '@' , str(dateTime)) | |
while True: | |
data = conn.recv(1024) | |
if not data: | |
break | |
conn.sendall(data) | |
while True: | |
print("Starting listener on: " , HOST ,':', str(PORT)) | |
try: | |
listener() | |
except: | |
pass | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment