Skip to main content

对 socket 简单的封装

Project description

Remote CLI

一个对socket简单的封装

有时候会碰到通过 nc 来交互的 miscs 或者 crypto 题, 于是就想着做个简单的封装吧
省的大佬们手输答案233

Examples

server

def handle(subsck):
    cli = remoteCLI.CLI()
    cli.sck = subsck
    cli.sendLine("100 rounds test, are you ready?")

    for i in range(100):
        x = random.randint(0, 100)
        y = random.randint(0, 100)

        cli.sendLine(str(x)+' + '+str(y)+' = ?')
        answer = cli.recvline()
        print(x, y, answer)

        if int(answer) == x+y:
            if i == 99:
                cli.sendLine("Congratulations, you got it.")
        else:
            cli.sendLine("Oops, better luck next time.")
            break

    cli.sck.close()
    return


mainsck = socket.socket()
mainsck.bind(("127.0.0.1", 12345))
mainsck.listen()

while True:
    subsck, addr = mainsck.accept()
    print(str(addr)+"connected")
    threading.Thread(target=handle, args=(subsck,)).start()

client

cli = remoteCLI.CLI()
cli.connect("127.0.0.1", 12345)
print(cli.recvline())

for i in range(100):
    paras = cli.recvUntilFind(r"([0-9]{1,}) \+ ([0-9]{1,})")
    answer = int(paras[0]) + int(paras[1])
    print(i, paras, answer)
    cli.sendLine(str(answer))

cli.console()

output

100 rounds test, are you ready? 0 ['29', '33'] 62
1 ['40', '34'] 74
...
...
99 ['7', '43'] 50
= ?
Congratulations, you got it.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for remoteCLI, version 0.3
Filename, size File type Python version Upload date Hashes
Filename, size remoteCLI-0.3.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page