Skip to content
Permalink
9d60e49744
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
50 lines (40 sloc) 1.17 KB
#!/usr/bin/python3
import socket
import random
import os
portOptions=[37000+x*100+x*2 for x in range(9)]
print(portOptions)
port=random.choice(portOptions)
hostname=socket.gethostname()
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind((hostname, port))
os.system("""ifconfig eth0|grep inet[^6]|cut -d " " -f 10""")
print(f"Serving on port {port}")
serversocket.listen()
response1=b"57 65 6c 63 6f 6d 65 20 74 6f 20 57 79 64 61 68"
class WydSock:
def __init__(self, sock):
self.sock = sock
def send(self, msg):
self.sock.sendall(msg)
def rcv(self):
chunks = []
bytes_recd = 0
chunks=[]
while bytes_recd <=0:
chunk = self.sock.recv(1024)
chunks.append(chunk)
bytes_recd = len(chunk)
return b''.join(chunks)
def close(self):
self.sock.shutdown(socket.SHUT_RDWR)
self.sock.close()
while True:
(clientsocket, address) = serversocket.accept()
print(f"Got a connection from {address}")
s=WydSock(clientsocket)
s.send(response1)
s.close()
serversocket.shutdown(socket.SHUT_RDWR)
serversocket.close()
break