Ejemplo n.º 1
0
    log("Listening on {}.".format(pp_host(HOST_PAIR)))
    conn = None
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.settimeout(3)
    listener.bind(HOST_PAIR)
    listener.listen(1)

    password = random.choice(PASSWORDS)
    log("Set password to '{}'.".format(password))

    while True:
        conn, sender = listener.accept()
        set_conn(conn)
        log("Got a connection from {}.".format(pp_host(sender)))
        send("PASSWORDPLS")
        data = receive()
        if data == password:
            send("OK")
            data = receive()
            if data == "FLAGPLS":
                send("<3><")
        else:
            send("BAD PASSWORD")
        close_conn()
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    close_conn()
Ejemplo n.º 2
0
set_name("Server")

try:
    log("Listening on {}.".format(pp_host(HOST_PAIR)))
    conn = None
    listener = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    listener.settimeout(3)
    listener.bind(HOST_PAIR)
    listener.listen(1)

    conn, sender = listener.accept()
    set_conn(conn)
    log("Got a connection from {}.".format(pp_host(sender)))
    data = True
    while data and data != "FLAGPLS":
        data = receive()
        if data and data != "FLAGPLS":
            log("Ignoring.")
    if data:
        send("><3>")
        log("Sent the flag.")
    else:
        log("Lost client.")
except socket.error, e:
    log("-!- {}".format(str(e)))
except KeyboardInterrupt:
    log("Killed.")
finally:
    log("Closing socket.")
    if conn:
        conn.shutdown(socket.SHUT_RDWR)