Small script to simplify network communication
Project description
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)
# or IPv6
f = Sock6("::1 3123", timeout=3)
# or already existing socket
f = Sock.from_socket(some_socket) # or toSock(some_socket)
# or UDP/IPv6
f = SockU6("::1 3123", timeout=3)
# or WebSocket
# For using WebSock, the websocket-client module must be installed (pip install websocket-client).
f = WebSock("ws://localhost:3123")
# wait for prompt (skip banner for example)
# the prompt itself will be skipped (and returned) too
f.read_until("> ", timeout=3) # read_until_re also exists
f.send("flip coin\n")
# skip until regexp
result1 = f.skip_until_re(r"You've got (heads|tails)") # skip_until(str) also exists
# read until also consumes matched part
f.read_until_re(r"You've g[oe]t ") # read_until(str) also exists
# read specific number of bytes
result2 = f.read_nbytes(5)
assert result1 == result2
# alias for f.send(s + "\n")
f.send_line("random please")
# read one packet and flush buffers
print(f.read_one())
# non-blocking read (flush buffers)
print(f.read_one(0))
# read until disconnect
print(f.read_all())
About
Author: hellman
License: MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sock-0.6.0.tar.gz
(5.9 kB
view details)
Built Distribution
sock-0.6.0-py3-none-any.whl
(5.8 kB
view details)
File details
Details for the file sock-0.6.0.tar.gz
.
File metadata
- Download URL: sock-0.6.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.0rc1 CPython/3.8.5 Linux/5.8.0-33-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 650717677a8b0e35e42dba19cecbd0ec0c922b67003e7e0c3e18ebb425a305cb |
|
MD5 | 1bc3e35ce36dcb79ed800594f32286bf |
|
BLAKE2b-256 | b3773507dd7e40cd5ccac1ef9fa102fbc2b39d6267500e0e7dba4b2d84625f41 |
File details
Details for the file sock-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: sock-0.6.0-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.0rc1 CPython/3.8.5 Linux/5.8.0-33-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e5cd3fab67042d6de06bbfedc8a3b9624de564bb64324531e508892145b30cf |
|
MD5 | 36ab8bd1a223bf0523e3c4b88851266c |
|
BLAKE2b-256 | b6b82faf49af564a08209b9fc822389cefd6268d81a1614b5f435a4835f14d8d |