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.25.tar.gz (21.5 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.25-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (900.6 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

new_year_2026-1.1.25-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (890.0 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ i686

new_year_2026-1.1.25-cp39-cp39-macosx_11_0_arm64.whl (76.0 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

new_year_2026-1.1.25-cp39-cp39-macosx_10_9_x86_64.whl (78.0 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: new_year_2026-1.1.25.tar.gz
  • Upload date:
  • Size: 21.5 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.25.tar.gz
Algorithm Hash digest
SHA256 630db1632d0b64d193330a03be1052b1bd14ccdeef3413c0336d88ceb653893c
MD5 0b9fda63133bdc67bf738f3f9ed17035
BLAKE2b-256 0b2a29c8a59771a0c28ee5e2b0f90f2aeb6df5ca99f3d89321f75d2da692895e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.25-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4b8501ef06e7106880d5aacd0abbbc16e225673684d6f926d3247689e79cfac
MD5 fa62728b281f75c8ae46b5c2de41ba89
BLAKE2b-256 3656007871e9498aa2b7ef854a3338d582ddb805026322f574e5250cdf0f0fe8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.25-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 6715f90f71d214f9a1384163d42c8f32cb09ed93e593fecd1edab3988b3a0061
MD5 7d0952f6d4e1ef56f7eb8e781cdffaf8
BLAKE2b-256 0de9b4065a265710b6e8e2689c095c348db372dc5eab85c34d111ed91f56be41

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.25-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 788ea671ac65a90816e4d6f785f3eac26ee5a28d7bb0c413cd147cb72ec51706
MD5 c98f1ee4fd8aef8ba0a3200dd7a84b90
BLAKE2b-256 05bb5170d1d4bdc9a0e093f154755c24928ab2c84a369f4a7ae2312f9bb97892

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.25-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 044ce2fb1324843687abd27703042e458e75391e5ae9de54a223b629deadf76c
MD5 cc9100c419d90c63b5c462234a4857f7
BLAKE2b-256 9677667faed5e65cb2f70f59237fab08ddd3e5963b89a5559224e46466213b3b

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