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.27.tar.gz (22.0 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.27-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (900.7 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

new_year_2026-1.1.27-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl (890.2 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ i686

new_year_2026-1.1.27-cp39-cp39-macosx_11_0_arm64.whl (76.1 kB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

new_year_2026-1.1.27-cp39-cp39-macosx_10_9_x86_64.whl (78.2 kB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

File details

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

File metadata

  • Download URL: new_year_2026-1.1.27.tar.gz
  • Upload date:
  • Size: 22.0 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.27.tar.gz
Algorithm Hash digest
SHA256 0c56089e11b16376e0e2cf61957d1cc9be829e5152ea43d13201f8212f96fb6f
MD5 ee3f40eece3c49a78c7a274011496091
BLAKE2b-256 7a1209b7f3645d54729736c0402e44c19dd9d27ad32359a5ed7cc142fbf985cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.27-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f4468a7737cfdacf12dd8bf970f1d5b750aa5dc27fd4a97a2a4a9206bf00c740
MD5 0fce0b65383b292087670777418e2be8
BLAKE2b-256 5da102ee2053ee9b76e09f63c4b9450936c1af1a92c3049e88033bdfaa86bdc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.27-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 b545e133678f96feb5ae0655b1e08a0bf0fdeff68490ac464a11196942b8ad10
MD5 64bf80cbfe7ac54d3c1f9f40791403dd
BLAKE2b-256 f7e6319d6bffe67b91133f04fd34a07641a4e590996355ccfa14e475997428ab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.27-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e25538c2bdeac32796a0eb7d947785af4d1a444b94586a781aff37d6d6d1b5f5
MD5 d4736f300a551b564f63bb8b7fb73f17
BLAKE2b-256 38406df9950ec7c58db44b1e1f2a7481c6a5c102bb97c26b216bae45fd0e41b2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for new_year_2026-1.1.27-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 851d6498de86ef92225e0d6f7ac715f2c5e8ab7d8c2bf064ae65eb03dfc8a2d8
MD5 e63dc4499c9bdea3dbd5c67831622a79
BLAKE2b-256 fe4b92722ed986c1f6c15fe62a73be60b3350604a18bd7ba809afa3dfd75643d

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