Skip to main content

TCP/TLS/HTTP/SSH learning scripts and demos.

Project description

2026 New Year 练习项目

Documentation Status CI Release Docs

本仓库包含一组用于学习 TCP/TLS 基础通信、HTTP 请求与证书配置的示例脚本。所有示例均以 Python 编写,适合用于本地或内网环境中学习网络编程与 TLS 加密流程。

文档地址:https://2026-new-year.readthedocs.io/en/stable/ 测试一下

目录结构

文件 作用说明
tcp_tls/tcp_server.py 经典 TCP 回显服务器示例,监听端口并返回客户端发送内容。
tcp_tls/tcp_client.py TCP 客户端示例,与 tcp_server.py 配套。
tcp_tls/tls_echo_server.py 基于 TLS 的回显服务端,使用本仓库的证书与私钥。
tcp_tls/tls_echo_client.py TLS 回显客户端示例,与 tls_echo_server.py 配套。
tcp_tls/mini_tls_server.py 简化版 TLS 服务端示例,演示证书加载与加密通信流程。
tcp_tls/get_or_post.py 简单 HTTP 请求示例,可执行 GET/POST 以练习应用层协议。
tcp_tls/ssh_minimal_client.py 最小 SSH 连接示例,仅完成 banner 交换。
tcp_tls/cert.pem 自签名证书(用于本地测试)。
tcp_tls/key.pem 自签名证书私钥(用于本地测试)。

环境准备

  • Python 3.8 及以上版本
  • 本地可用的终端或命令行环境

建议新建虚拟环境进行练习(可选):

python -m venv .venv
source .venv/bin/activate

快速开始

1. 运行 TCP 回显示例

启动服务端:

python -m new_year_2026.tcp_tls.tcp_server

在另一终端启动客户端:

python -m new_year_2026.tcp_tls.tcp_client

客户端发送的内容会被服务端原样返回,用于验证基础 TCP 通信。

2. 运行 TLS 回显示例

启动 TLS 服务端:

python -m new_year_2026.tcp_tls.tls_echo_server

再运行客户端:

python -m new_year_2026.tcp_tls.tls_echo_client

此示例展示如何在 TCP 之上加入 TLS 加密层。若需要替换证书,请同时更新 tcp_tls/cert.pemtcp_tls/key.pem

3. 运行简化 TLS 服务端

python -m new_year_2026.tcp_tls.mini_tls_server

该脚本提供更紧凑的实现方式,适合阅读或二次修改。

4. 运行 HTTP GET/POST 示例

python -m new_year_2026.tcp_tls.get_or_post

脚本会执行一次 HTTP 请求,适合配合抓包工具学习 HTTP 报文格式。

5. 运行最小 SSH 连接示例

python -m new_year_2026.tcp_tls.ssh_minimal_client

该脚本只完成 SSH 的识别字符串(banner)交换,不包含密钥协商、加密与认证流程。默认连接 127.0.0.1:22,请根据需要修改 HOSTPORT

常见问题

证书不被信任怎么办?

当前 tcp_tls/cert.pem 为自签名证书,系统默认不会信任。用于本地学习时可忽略该告警;如需生产环境使用,请替换为权威机构签发证书。

端口占用或无法绑定?

请确认没有其他程序占用对应端口,或调整脚本中的端口配置后再运行。

练习建议

  • tcp_tls/tcp_server.py 改为多线程/异步版本,体验并发处理。
  • 修改 TLS 示例,尝试双向认证(mTLS)。
  • tcp_tls/get_or_post.py 添加自定义头部或 JSON 请求体。

本地扩展与共享库示例

  • src/new_year_2026/ctypes_shared:构建 .so/.dylib/.dll 并用 ctypes 加载调用。
  • src/new_year_2026/hello_ext:主包内的 C/C++ 扩展示例,构建产物在 macOS/Linux 为 .so,在 Windows 为 .pyd

许可说明

本仓库仅用于学习与教学示例,证书与私钥仅用于本地测试,请勿在生产环境直接使用。

Project details


Download files

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

Source Distribution

new_year_2026-1.1.24.tar.gz (21.1 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

new_year_2026-1.1.24-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (900.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

new_year_2026-1.1.24-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (889.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ i686

new_year_2026-1.1.24-cp39-cp39-macosx_11_0_arm64.whl (75.3 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

new_year_2026-1.1.24-cp39-cp39-macosx_10_9_x86_64.whl (77.4 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

Details for the file new_year_2026-1.1.24.tar.gz.

File metadata

  • Download URL: new_year_2026-1.1.24.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for new_year_2026-1.1.24.tar.gz
Algorithm Hash digest
SHA256 c21974c05c8aeb465a22ab82187c4553a66bc9db242143cd59b5ba4fbfa64a6e
MD5 b04fb1b17ff83393cc8341c2d479a11c
BLAKE2b-256 a4ef8bad1a82d5ea2b2df9a9ea03cbeeded33154d60aa1b4009cf97e0696fe59

See more details on using hashes here.

File details

Details for the file new_year_2026-1.1.24-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for new_year_2026-1.1.24-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99751dd481bf46cac8132f07c44b5838bf9dfb705685b130475022ddc5a3bf69
MD5 ecad85edaabcf560fa6e97e3b747d151
BLAKE2b-256 2617328ecdb7400e9c4cb2981f0d07377c927f3b559add67edae456aabaa9473

See more details on using hashes here.

File details

Details for the file new_year_2026-1.1.24-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for new_year_2026-1.1.24-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 114d95ecc6be1cd4b28723b7fb059b6f9c87da7cd5632c71437b6f21e67c7dce
MD5 1d9e60b2b2ac7340fa3070dbdb9c26e8
BLAKE2b-256 ecfb6b76a59c0201e93aba386db1efe4af2e5eca083a231e4ee294744da0d248

See more details on using hashes here.

File details

Details for the file new_year_2026-1.1.24-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for new_year_2026-1.1.24-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ac6e8d6ff96868504948a96bc8edb873699690014a264f8f1bd02876710e38e8
MD5 8516463c51e17a719917a176821f5696
BLAKE2b-256 09ff55fecf2fe302330e0ac16ef9589e4cf4dffa97c6ecec55c33c40b4939050

See more details on using hashes here.

File details

Details for the file new_year_2026-1.1.24-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for new_year_2026-1.1.24-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 d4c02a1f7051171379548a80952f59d591f5b14c985d1ef8b62a1b7f98abb4ae
MD5 61f5fb05ff9e448e7ffed6a19cbaa613
BLAKE2b-256 e6d17e1b3c3b0aeee588d6386f7dcfdb1c37ece6b9e0f3b7a09cf448d5567cad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page