Commit 674b2776 authored by daniel421's avatar daniel421
Browse files

Add server file

parent 631197e1
#!/usr/bin/env python
import random
import socket
from pprint import pprint
import signal
import sys
def signal_handler(sig, frame):
print('You pressed Ctrl+C!')
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
HOST='127.0.0.1'
PORT=55555
# Param
max_size=100
# Generate entry
rand_gen=[]
random.seed(2)
for i in range(max_size):
rand_gen.append(random.randint(0, 65335))
random.seed()
seq=[]
debut = random.randint(0, max_size-11)
for i in range(debut, debut+11):
seq.append(rand_gen[i])
# Start the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((HOST, PORT))
print "Server started: " + HOST + ":" + str(PORT)
s.listen(5)
conn, addr = s.accept()
conn.send(str(seq[0])+"\n")
conn.send("\nFind next number: ")
guess = 0
inputed = int(conn.recv(10))
for i in seq[1:]:
pprint(inputed)
pprint(i)
pprint(inputed == i)
print ""
if inputed == i:
guess+=1
conn.send("What's next ?\n")
else:
conn.send("Nope, let's try again\n")
conn.send(str(i)+"\n")
conn.send("Guessed: " + str(guess) + "/10\n")
conn.send("\nFind next number: ")
inputed = int(conn.recv(10))
if guess == 10:
conn.send("OK... you're lucky, here's the flag: FLAG{RPGN}")
else:
conn.send("Bad news... no flag for you")
s.close()
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment