sock
Small script to simplify network communication.
Something like telnetlib, but for clean TCP/UDP (no command sequences, \r\n newlines, etc.)
As an alternative, consider pwntools which contains unified interface (tubes) for communications with sockets, processes, etc. See tubes API.
Current development only supports python 3. Old python 2 version is available at the py2 branch.
Installation
$ pip3 install sock
For development or building from this repository, poetry is needed.
Usage
TCP Client
from sock import *
f = Sock("some.cool.servi.ce:3123", timeout=10)
f = Sock6("::1 3123", timeout=3)
f = Sock.from_socket(some_socket)
f = SockU6("::1 3123", timeout=3)
f = WebSock("ws://localhost:3123")
f.read_until("> ", timeout=3)
f.send("flip coin\n")
result1 = f.skip_until_re(r"You've got (heads|tails)")
f.read_until_re(r"You've g[oe]t ")
result2 = f.read_nbytes(5)
assert result1 == result2
f.send_line("random please")
print(f.read_one())
print(f.read_one(0))
print(f.read_all())
About
Author: hellman
License: MIT License