{"id":27290767,"url":"https://github.com/hellman/sock","last_synced_at":"2025-04-11T21:38:55.251Z","repository":{"id":4260659,"uuid":"5387431","full_name":"hellman/sock","owner":"hellman","description":"Small scripts to simplify network communication","archived":false,"fork":false,"pushed_at":"2020-12-27T16:43:15.000Z","size":33,"stargazers_count":27,"open_issues_count":0,"forks_count":9,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-04T11:05:52.530Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hellman.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-12T09:35:55.000Z","updated_at":"2022-02-25T18:43:02.000Z","dependencies_parsed_at":"2022-08-06T15:16:52.289Z","dependency_job_id":null,"html_url":"https://github.com/hellman/sock","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fsock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fsock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fsock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellman%2Fsock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellman","download_url":"https://codeload.github.com/hellman/sock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248485383,"owners_count":21111845,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-11T21:38:54.272Z","updated_at":"2025-04-11T21:38:55.234Z","avatar_url":"https://github.com/hellman.png","language":"Python","readme":"# sock\n\nSmall script to simplify network communication.\n\nSomething like [telnetlib](http://docs.python.org/library/telnetlib.html), but for clean TCP/UDP (no command sequences, \\r\\n newlines, etc.)\n\nAs an alternative, consider [pwntools](http://pwntools.com/) which contains unified interface (tubes) for communications with sockets, processes, etc. See [tubes API](http://pwntools.com/).\n\nCurrent development only supports python 3. Old python 2 version is available at the py2 branch.\n\n## Installation\n\n```bash\n$ pip3 install sock\n```\n\nFor development or building from this repository, [poetry](https://python-poetry.org/) is needed.\n\n## Usage\n\n### TCP Client\n\n```python\nfrom sock import *\n\nf = Sock(\"some.cool.servi.ce:3123\", timeout=10)\n# or IPv6\nf = Sock6(\"::1 3123\", timeout=3)\n# or already existing socket\nf = Sock.from_socket(some_socket)  # or toSock(some_socket)\n# or UDP/IPv6\nf = SockU6(\"::1 3123\", timeout=3)\n# or WebSocket\n# For using WebSock, the websocket-client module must be installed (pip install websocket-client).\nf = WebSock(\"ws://localhost:3123\")\n\n# wait for prompt (skip banner for example)\n# the prompt itself will be skipped (and returned) too\nf.read_until(\"\u003e \", timeout=3)  # read_until_re also exists\n\nf.send(\"flip coin\\n\")\n\n# skip until regexp\nresult1 = f.skip_until_re(r\"You've got (heads|tails)\")  # skip_until(str) also exists\n\n# read until also consumes matched part\nf.read_until_re(r\"You've g[oe]t \")  # read_until(str) also exists\n\n# read specific number of bytes\nresult2 = f.read_nbytes(5)\n\nassert result1 == result2\n\n# alias for f.send(s + \"\\n\")\nf.send_line(\"random please\")\n\n# read one packet and flush buffers\nprint(f.read_one())\n\n# non-blocking read (flush buffers)\nprint(f.read_one(0))\n\n# read until disconnect\nprint(f.read_all())\n```\n\n\nAbout\n---------------------\n\nAuthor: hellman\n\nLicense: [MIT License](http://opensource.org/licenses/MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellman%2Fsock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellman%2Fsock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellman%2Fsock/lists"}