Пример #1
0
import socket
import random

from tcp_tools import set_name, set_conn, close_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2005)
PASSWORDS = [
    "red", "blue", "gray", "purple", "elephant", "monkey", "lion", "tiger",
    "bear", "password", "hunter", "dog", "cat", "swordfish"
]

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)

    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()
Пример #2
0
#!/usr/bin/python

import socket

from tcp_tools import set_name, set_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2001)

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.")
Пример #3
0
#!/usr/bin/python

import socket

from tcp_tools import set_name, set_conn, close_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2001)

set_name("Client")

try:
    log("Connecting on {}.".format(pp_host(HOST_PAIR)))
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    set_conn(sock)
    sock.connect(HOST_PAIR)
    data = receive()
    if data.startswith("CHALLENGE"):
        operands = [None, None]
        challenge, operands[0], operator, operands[1] = data.split()
        operands = map(int, operands)
        if operator == '+':
            answer = operands[0] + operands[1]
        elif operator == '-':
            answer = operands[0] - operands[1]
        elif operator == '*':
            answer = operands[0] * operands[1]
        else:
            answer = operands[0] / operands[1]
        send(answer)
        data = receive()
        if data == "OK":
Пример #4
0
#!/usr/bin/python

import socket

from tcp_tools import set_name, set_conn, close_conn, log, pp_host, send, receive

HOST_PAIR = ("127.0.0.1", 2001)

set_name("Client")

try:
    log("Connecting on {}.".format(pp_host(HOST_PAIR)))
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    set_conn(sock)
    sock.connect(HOST_PAIR)
    data = receive()
    if data.startswith("CHALLENGE"):
        operands = [None, None]
        challenge, operands[0], operator, operands[1] = data.split()
        operands = map(int, operands)
        if operator == "+":
            answer = operands[0] + operands[1]
        elif operator == "-":
            answer = operands[0] - operands[1]
        elif operator == "*":
            answer = operands[0] * operands[1]
        else:
            answer = operands[0] / operands[1]
        send(answer)
        data = receive()
        if data == "OK":