dsh-ptforge 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dsh_ptforge-0.1.0/LICENSE +28 -0
- dsh_ptforge-0.1.0/NOTICE +28 -0
- dsh_ptforge-0.1.0/PKG-INFO +417 -0
- dsh_ptforge-0.1.0/README.md +384 -0
- dsh_ptforge-0.1.0/dsh_ptforge.egg-info/PKG-INFO +417 -0
- dsh_ptforge-0.1.0/dsh_ptforge.egg-info/SOURCES.txt +117 -0
- dsh_ptforge-0.1.0/dsh_ptforge.egg-info/dependency_links.txt +1 -0
- dsh_ptforge-0.1.0/dsh_ptforge.egg-info/entry_points.txt +3 -0
- dsh_ptforge-0.1.0/dsh_ptforge.egg-info/requires.txt +6 -0
- dsh_ptforge-0.1.0/dsh_ptforge.egg-info/top_level.txt +1 -0
- dsh_ptforge-0.1.0/ptforge/__init__.py +3 -0
- dsh_ptforge-0.1.0/ptforge/__main__.py +3 -0
- dsh_ptforge-0.1.0/ptforge/assets/port_names.json +826 -0
- dsh_ptforge-0.1.0/ptforge/assets/skeleton_8.1.1.xml +16629 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/1841.xml +298 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/1941.xml +488 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2620XM.xml +225 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2621XM.xml +264 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2811.xml +307 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2901.xml +378 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2911.xml +417 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2950-24.xml +557 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2950T-24.xml +617 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/2960-24TT.xml +599 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/3560-24PS.xml +1254 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/5505.xml +525 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/7960.xml +144 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/819HG-4G-IOX.xml +2567 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/819HGW.xml +806 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/829.xml +3125 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/AccessPoint-PT-A.xml +85 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/AccessPoint-PT-N.xml +85 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/AccessPoint-PT.xml +85 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Air Conditioner.xml +486 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Analog-Phone-PT.xml +75 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Appliance(0).xml +468 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Atm Pressure Monitor(0).xml +484 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Battery.xml +837 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Beacon.xml +410 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Bluetooth Speaker.xml +603 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/CGR1240.xml +760 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/CO Detector.xml +550 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Carbon Dioxide Detector.xml +533 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Cell-Tower.xml +191 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Central-Office-Server.xml +371 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Cloud-PT.xml +250 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/DLC100.xml +473 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/DSL-Modem-PT.xml +102 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Door.xml +701 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Fire Sprinkler.xml +507 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Furnace.xml +536 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Garage Door.xml +553 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Home Speaker.xml +609 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Home-VoIP-PT.xml +382 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/HomeRouter-PT-AC.xml +603 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Hub-PT.xml +226 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Humidifier.xml +529 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Humidity Monitor.xml +446 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/IE-2000.xml +334 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/ISR4321.xml +601 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/ISR4331.xml +664 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/LAP-PT.xml +151 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/LED.xml +405 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Laptop-PT.xml +451 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Light.xml +552 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Linksys-WRT300N.xml +289 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/MCU-PT.xml +357 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Meraki-MX65W.xml +533 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Meraki-Server.xml +2371 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/NetworkController.xml +1433 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Old Car.xml +452 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/PC-PT.xml +622 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Portable Music Player.xml +591 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Potentiometer.xml +394 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Power Distribution Device.xml +49 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Power Meter.xml +517 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Push Button.xml +373 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/RGB LED.xml +385 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Rocker Switch.xml +366 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Router-PT.xml +545 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/SBC-PT.xml +388 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/SMARTPHONE-PT.xml +551 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Server-PT.xml +1959 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Smart LED.xml +467 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Sniffer.xml +97 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Solar Panel.xml +567 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Switch-PT.xml +358 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/TabletPC-PT.xml +537 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Thermostat.xml +789 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Thing.xml +461 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/WLC-2504.xml +369 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/WLC-3504.xml +447 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/WLC-PT.xml +207 -0
- dsh_ptforge-0.1.0/ptforge/assets/templates/Window.xml +569 -0
- dsh_ptforge-0.1.0/ptforge/build.py +436 -0
- dsh_ptforge-0.1.0/ptforge/catalog.py +192 -0
- dsh_ptforge-0.1.0/ptforge/cli.py +520 -0
- dsh_ptforge-0.1.0/ptforge/doctor.py +83 -0
- dsh_ptforge-0.1.0/ptforge/edit.py +183 -0
- dsh_ptforge-0.1.0/ptforge/gui.py +417 -0
- dsh_ptforge-0.1.0/ptforge/guitool.py +213 -0
- dsh_ptforge-0.1.0/ptforge/launch.py +108 -0
- dsh_ptforge-0.1.0/ptforge/notes.py +137 -0
- dsh_ptforge-0.1.0/ptforge/patch.py +164 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/__init__.py +6 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/cmac.py +58 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/ctr.py +33 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/eax.py +53 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/pt_crypto.py +46 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/ptfile.py +168 -0
- dsh_ptforge-0.1.0/ptforge/ptcrypto/twofish.py +393 -0
- dsh_ptforge-0.1.0/ptforge/report.py +136 -0
- dsh_ptforge-0.1.0/ptforge/runtime.py +320 -0
- dsh_ptforge-0.1.0/ptforge/spec.py +234 -0
- dsh_ptforge-0.1.0/ptforge/state.py +276 -0
- dsh_ptforge-0.1.0/ptforge/web.py +106 -0
- dsh_ptforge-0.1.0/pyproject.toml +65 -0
- dsh_ptforge-0.1.0/setup.cfg +4 -0
- dsh_ptforge-0.1.0/tests/test_engine.py +342 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chiyan11
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
Scope note: this license covers the code written for ptforge. The Twofish
|
|
26
|
+
implementation under ptforge/ptcrypto/twofish.py is a vendored third-party work
|
|
27
|
+
(Gladman/Paulo Barreto reference implementation, redistributed via
|
|
28
|
+
pshvatov/pka-decipher) and is NOT relicensed by this notice; see NOTICE.
|
dsh_ptforge-0.1.0/NOTICE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
## Twofish / CMAC / CTR / EAX
|
|
4
|
+
|
|
5
|
+
Files under `ptforge/ptcrypto/`:
|
|
6
|
+
|
|
7
|
+
- `twofish.py` — Twofish reference implementation by Paulo Barreto and
|
|
8
|
+
Vincent Rijmen, as distributed by pshvatov/pka-decipher. The file carries the
|
|
9
|
+
original Gladman-style copyright header; keep it intact when redistributing.
|
|
10
|
+
- `cmac.py`, `ctr.py`, `eax.py`, `pt_crypto.py` — thin helpers derived from the
|
|
11
|
+
same upstream repository.
|
|
12
|
+
|
|
13
|
+
The upstream repository (https://github.com/pshvatov/pka-decipher) does not ship
|
|
14
|
+
a top-level LICENSE file at the time of writing. That means the cryptographic
|
|
15
|
+
code is redistributed **without an explicit license grant**. The MIT license in
|
|
16
|
+
this repository covers only the code authored for ptforge. If you intend to
|
|
17
|
+
redistribute ptforge commercially or under a different license, replace the
|
|
18
|
+
vendored cipher with a properly licensed implementation (for example the
|
|
19
|
+
`twofish` package on PyPI) or obtain permission from the upstream authors.
|
|
20
|
+
|
|
21
|
+
## Everything else
|
|
22
|
+
|
|
23
|
+
`ptforge/`, `packages/dsh-ptforge/`, `docs/`, `tests/` and `scripts/` are
|
|
24
|
+
original work, MIT licensed (see LICENSE).
|
|
25
|
+
|
|
26
|
+
The `.pkt` container format and the Cisco IOS command syntax emulated here are
|
|
27
|
+
undocumented/proprietary interfaces of Cisco Packet Tracer. This project is not
|
|
28
|
+
affiliated with or endorsed by Cisco Systems.
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: dsh-ptforge
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Declarative Cisco Packet Tracer automation: offline .pkt codec, topology builder, state assertions, and a minimal Win32 runtime.
|
|
5
|
+
Author: chiyan11
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/chiyan11/dsh-ptforge
|
|
8
|
+
Project-URL: Issues, https://github.com/chiyan11/dsh-ptforge/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/chiyan11/dsh-ptforge/blob/main/docs/TOOLS.md
|
|
10
|
+
Keywords: packet-tracer,cisco,network-simulation,automation,deepseek-harness
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Education
|
|
14
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Education
|
|
23
|
+
Classifier: Topic :: System :: Networking
|
|
24
|
+
Requires-Python: >=3.10
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
License-File: NOTICE
|
|
28
|
+
Provides-Extra: gui
|
|
29
|
+
Requires-Dist: Pillow>=10.0; extra == "gui"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# ptforge
|
|
35
|
+
|
|
36
|
+
**Cisco Packet Tracer 自动化引擎 · DeepSeek Harness 插件**
|
|
37
|
+
|
|
38
|
+
[](https://github.com/chiyan11/dsh-ptforge/actions/workflows/ci.yml)
|
|
39
|
+
[](pyproject.toml)
|
|
40
|
+
[](LICENSE)
|
|
41
|
+
|
|
42
|
+
> Packet Tracer 没有公开的自动化 API,也没有可编程接口进它的 CLI 引擎。ptforge 用两条互补的路径把这件事做通:
|
|
43
|
+
> **容器级离线编辑**(直接读写 `.pkt`,覆盖拓扑、连线、配置、网页、标注)+ **最小 GUI 运行时**(在真窗口里执行命令、拿到回显、做断言)。
|
|
44
|
+
|
|
45
|
+
`ptforge` 提供 18 个 `pt_*` 工具,覆盖「造拓扑 → 配设备 → 离线验收 → 真机验收 → 出报告」的完整闭环;
|
|
46
|
+
它同时是一个可 `pip install` 的纯 Python 包和一个可在 Linux 容器里跑的离线工具链。
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 目录
|
|
51
|
+
|
|
52
|
+
- [为什么需要它](#为什么需要它)
|
|
53
|
+
- [能力矩阵](#能力矩阵)
|
|
54
|
+
- [架构](#架构)
|
|
55
|
+
- [安装](#安装)
|
|
56
|
+
- [打包与容器化](#打包与容器化)
|
|
57
|
+
- [快速开始](#快速开始)
|
|
58
|
+
- [工具参考](#工具参考)
|
|
59
|
+
- [命令行](#命令行)
|
|
60
|
+
- [验收与测试](#验收与测试)
|
|
61
|
+
- [已知边界](#已知边界)
|
|
62
|
+
- [目录结构](#目录结构)
|
|
63
|
+
- [第三方代码](#第三方代码)
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## 为什么需要它
|
|
68
|
+
|
|
69
|
+
Packet Tracer 8.x 的 `PacketTracer.exe` 里没有 `PTAPI`、没有 socket 服务,`plugins/` 只接受 Cisco 签名的二进制插件,`extensions/*.pts` 是加密脚本。官方没有给外部程序留任何编程入口。
|
|
70
|
+
|
|
71
|
+
因此自动化只有两种可能:
|
|
72
|
+
|
|
73
|
+
| 路径 | 可行性 | ptforge 的取舍 |
|
|
74
|
+
| --- | --- | --- |
|
|
75
|
+
| GUI 自动化(点击画布、敲终端) | 可行但脆弱:需要窗口焦点、坐标随缩放/滚动变化、终端只能逐键输入 | 只保留**必要**的运行时能力(执行命令、回显、断言、业务动作),其余全部走离线 |
|
|
76
|
+
| 直接读写 `.pkt` | 可行:容器是 Twofish-EAX + zlib 压缩的 `<PACKETTRACER5>` XML | 作为主力:拓扑、连线、配置、网页、标注都在这里完成 |
|
|
77
|
+
|
|
78
|
+
等价地说:**能离线证明的,绝不开窗口;只有运行时才有的状态(路由表、NAT 翻译、连通性、页面内容),才走 GUI。**
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 能力矩阵
|
|
83
|
+
|
|
84
|
+
| 能力 | 方式 | 工具 |
|
|
85
|
+
| --- | --- | --- |
|
|
86
|
+
| 查询型号与接口名 | 离线 | `pt_models` |
|
|
87
|
+
| 从 JSON spec 生成拓扑 | 离线 | `pt_build` |
|
|
88
|
+
| 增量修改(IP / 配置 / 改名 / VLAN / 删配置) | 离线 | `pt_patch` |
|
|
89
|
+
| 给单台设备写 IOS 配置 | 离线 | `pt_apply` |
|
|
90
|
+
| 拓扑清单与端口解析 | 离线 | `pt_inspect` |
|
|
91
|
+
| 结构化状态读取(接口、静态路由、NAT、ACL、VLAN) | 离线 | `pt_state` |
|
|
92
|
+
| 对 `.pkt` 做断言 | 离线 | `pt_check` |
|
|
93
|
+
| 画布标注 | 离线 | `pt_note` |
|
|
94
|
+
| 读写 Server-PT 网页 | 离线 | `pt_server_page` |
|
|
95
|
+
| 环境与版本体检 | 离线 | `pt_doctor` |
|
|
96
|
+
| 报告素材(图 + 图注 + 表格) | 离线 | `pt_report` |
|
|
97
|
+
| 打开文件并置前 | 运行时 | `pt_open` |
|
|
98
|
+
| 窗口焦点 / 点击 / 输入 / 截图(逃生舱) | 运行时 | `pt_gui` |
|
|
99
|
+
| 执行命令并回读 transcript | 运行时 | `pt_exec` |
|
|
100
|
+
| 带断言执行命令 | 运行时 | `pt_assert` |
|
|
101
|
+
| ping 与统计解析 | 运行时 | `pt_ping` |
|
|
102
|
+
| 浏览器取页面正文 | 运行时 | `pt_http_get` |
|
|
103
|
+
| FTP 会话 | 运行时 | `pt_ftp` |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 架构
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
spec.json
|
|
111
|
+
│
|
|
112
|
+
┌──────▼──────┐
|
|
113
|
+
│ spec.py │ 解析 / 自动布局 / 自动选线 / 自动配端口
|
|
114
|
+
└──────┬──────┘
|
|
115
|
+
│
|
|
116
|
+
┌──────▼──────┐ ptforge/assets/
|
|
117
|
+
│ build.py │◄─────── skeleton_8.1.1.xml
|
|
118
|
+
│ catalog.py │ templates/*.xml (80 型号)
|
|
119
|
+
└──────┬──────┘ port_names.json
|
|
120
|
+
│ ElementTree
|
|
121
|
+
┌──────▼──────┐
|
|
122
|
+
│ ptfile.py │ Twofish-EAX(zlib(level 6)) ⇄ <PACKETTRACER5>
|
|
123
|
+
└──────┬──────┘
|
|
124
|
+
│ .pkt
|
|
125
|
+
┌────────────┴─────────────┐
|
|
126
|
+
│ │
|
|
127
|
+
edit/state/patch/notes/ gui.py → 真 PT 窗口
|
|
128
|
+
web/report/doctor runtime.py(exec/assert/ping/http/ftp)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
- **容器层**:`ptcrypto/`(twofish、CMAC、CTR、EAX 的 vendored 实现)+ `ptfile.py` 负责加解密与压缩;`build.py` 用 8.1.1 骨架和 80 个设备模板拼装文档,并维护物理工作区节点、SAVE_REF_ID、端口顺序、`FROM/PORT/TO/PORT` 等 PT 强制约束。
|
|
132
|
+
- **语义层**:`state.py`、`patch.py`、`edit.py`、`notes.py`、`web.py`、`report.py` 只依赖 ElementTree,可以做增量修改与断言。
|
|
133
|
+
- **运行时层**:`gui.py` 只用 ctypes 调 Win32,`runtime.py` 在其上实现「粘贴命令 → 回车 → 拖选 → 右键 Copy」的控制台读回。PT 终端不接受合成逐键输入,但接受**右键 Paste**;回读只能取可见区域,因此长会话会保留过程中最长的一次快照。
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## 安装
|
|
138
|
+
|
|
139
|
+
### 依赖
|
|
140
|
+
|
|
141
|
+
| 部分 | 要求 |
|
|
142
|
+
| --- | --- |
|
|
143
|
+
| 核心引擎(构建 / 修改 / 断言 / 报告) | Python 3.10+,**无第三方依赖** |
|
|
144
|
+
| 运行时工具(`pt_exec` / `pt_ping` / `pt_http_get` / `pt_ftp` / `pt_gui`) | Windows 10/11 + Pillow,且桌面可交互 |
|
|
145
|
+
| Packet Tracer 本体 | **8.1.x**(`pt_doctor` 会校验文件版本;运行时工具需要 `PacketTracer.exe`) |
|
|
146
|
+
| DSH 插件形态 | DeepSeek Harness(bundle 宿主) |
|
|
147
|
+
|
|
148
|
+
### 方式一:pip 安装
|
|
149
|
+
|
|
150
|
+
PyPI 上的分发名是 **`dsh-ptforge`**(`ptforge` 已被另一个无关项目占用),import 包名仍是 `ptforge`,命令仍是 `ptforge` / `ptforge-gui`:
|
|
151
|
+
|
|
152
|
+
```powershell
|
|
153
|
+
pip install dsh-ptforge # 纯离线引擎,无依赖
|
|
154
|
+
pip install "dsh-ptforge[gui]" # 含 Pillow,可用 Windows 运行时工具
|
|
155
|
+
pip install "dsh-ptforge[gui,dev]" # 另含 pytest
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
安装后可直接使用两个入口:
|
|
159
|
+
|
|
160
|
+
```powershell
|
|
161
|
+
ptforge doctor
|
|
162
|
+
ptforge build lab.json -o lab.pkt
|
|
163
|
+
ptforge-gui exec R1 "show ip route"
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 方式二:以 DSH bundle 安装
|
|
167
|
+
|
|
168
|
+
```powershell
|
|
169
|
+
# 在 DSH 会话中
|
|
170
|
+
plugin_manager install_bundle target="D:\coding\daily\dsh-ptforge\packages\dsh-ptforge"
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
安装后 18 个 `pt_*` 工具会出现在工具列表里。插件把引擎副本打进包内,运行时不依赖仓库目录。
|
|
174
|
+
|
|
175
|
+
### 方式三:容器(仅离线引擎)
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
docker build -t ptforge:0.1.0 .
|
|
179
|
+
docker run --rm -v "$PWD:/work" ptforge:0.1.0 build lab.json -o lab.pkt
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
容器只包含离线引擎:Packet Tracer 是 Windows GUI 程序,`pt_exec` 这类运行时工具无法在 Linux 容器内工作(调用会给出明确错误)。
|
|
183
|
+
|
|
184
|
+
### 从源码调试
|
|
185
|
+
|
|
186
|
+
```powershell
|
|
187
|
+
cd D:\coding\daily\dsh-ptforge
|
|
188
|
+
$env:PYTHONPATH = (Get-Location).Path
|
|
189
|
+
python -m ptforge doctor
|
|
190
|
+
python -m ptforge models --query 2960
|
|
191
|
+
python -m unittest discover -s tests
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 打包与容器化
|
|
197
|
+
|
|
198
|
+
### Python 包
|
|
199
|
+
|
|
200
|
+
`pyproject.toml` 使用 setuptools 后端,包数据随 wheel 一起发布(8.1.1 骨架、80 个设备模板、端口命名表,约 2.7 MB):
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
ptforge/assets/skeleton_8.1.1.xml
|
|
204
|
+
ptforge/assets/templates/*.xml
|
|
205
|
+
ptforge/assets/port_names.json
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
构建与检查:
|
|
209
|
+
|
|
210
|
+
```powershell
|
|
211
|
+
python -m pip install build
|
|
212
|
+
python -m build # dist/*.whl + *.tar.gz
|
|
213
|
+
python -m twine check dist/* # 元数据校验
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
两个 console script 由 `[project.scripts]` 提供:`ptforge`(引擎 CLI)与 `ptforge-gui`(Win32 运行时 CLI)。版本号在 `pyproject.toml` 与 `ptforge/__init__.py` 两处维护。
|
|
217
|
+
|
|
218
|
+
### Docker 镜像
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
docker build -t ptforge:0.1.0 .
|
|
222
|
+
docker run --rm -v "$PWD:/work" ptforge:0.1.0 --help
|
|
223
|
+
docker run --rm -v "$PWD:/work" ptforge:0.1.0 build lab.json -o lab.pkt
|
|
224
|
+
docker run --rm -v "$PWD:/work" ptforge:0.1.0 inspect lab.pkt
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
设计要点:
|
|
228
|
+
|
|
229
|
+
- 基于 `python:3.12-slim`,以非 root 用户(uid 10001)运行,工作目录固定为 `/work`。
|
|
230
|
+
- 只 `COPY pyproject.toml README.md LICENSE ptforge/`,`.dockerignore` 排除测试、fixtures、bundle 与截图,镜像层保持最小。
|
|
231
|
+
- 入口为 `ptforge`,默认 `--help`;卷挂载当前目录即可读写 `.pkt`。
|
|
232
|
+
- 镜像内**不包含**运行时能力:`pt_exec`、`pt_ping`、`pt_http_get`、`pt_ftp`、`pt_gui` 依赖真实 Windows 窗口,容器内调用会直接报错而不是假装成功。
|
|
233
|
+
|
|
234
|
+
`docker-compose.yml` 提供了等价的一行式调用:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
docker compose run --rm ptforge build lab.json -o lab.pkt
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### CI
|
|
241
|
+
|
|
242
|
+
`.github/workflows/ci.yml` 在每次 push / PR 时执行三个 job:
|
|
243
|
+
|
|
244
|
+
| job | 内容 |
|
|
245
|
+
| --- | --- |
|
|
246
|
+
| `test` | Python 3.10 / 3.11 / 3.12 矩阵,跑 20 个单测 + `build → inspect → doctor → report` 冒烟 |
|
|
247
|
+
| `package` | 构建 wheel/sdist,并断言 wheel 内含骨架与 ≥80 个模板,产物作为 artifact 上传 |
|
|
248
|
+
| `docker` | 构建镜像并执行 `--help` |
|
|
249
|
+
|
|
250
|
+
### 发布到 PyPI(Trusted Publishing)
|
|
251
|
+
|
|
252
|
+
仓库自带 [`.github/workflows/publish.yml`](.github/workflows/publish.yml),用 OIDC 发布,**不需要在仓库里存 PyPI token**。首次发布前在 PyPI 的 *Publishing → Add a new pending publisher* 填:
|
|
253
|
+
|
|
254
|
+
| 字段 | 值 |
|
|
255
|
+
| --- | --- |
|
|
256
|
+
| PyPI Project Name | `dsh-ptforge` |
|
|
257
|
+
| Owner | `chiyan11` |
|
|
258
|
+
| Repository name | `dsh-ptforge` |
|
|
259
|
+
| Workflow name | `publish.yml` |
|
|
260
|
+
| Environment name | `pypi` |
|
|
261
|
+
|
|
262
|
+
然后在 GitHub 仓库 *Settings → Environments* 建一个名为 `pypi` 的环境(可选,但推荐,可加人工审批)。发布时二选一:
|
|
263
|
+
|
|
264
|
+
- 在 GitHub 创建 Release(tag 形如 `v0.1.0`)→ 自动构建并上传;
|
|
265
|
+
- 或手动跑 `publish` workflow。
|
|
266
|
+
|
|
267
|
+
构建 job 会再次断言 wheel 内含 8.1.1 骨架与 ≥80 个模板,避免发布一个缺资产的包。
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
271
|
+
## 快速开始
|
|
272
|
+
|
|
273
|
+
### 1. 用 spec 生成拓扑
|
|
274
|
+
|
|
275
|
+
```json
|
|
276
|
+
{
|
|
277
|
+
"name": "office_lan",
|
|
278
|
+
"devices": [
|
|
279
|
+
{"model": "2911", "name": "R1",
|
|
280
|
+
"config": ["hostname R1", "ip route 0.0.0.0 0.0.0.0 192.168.10.254"]},
|
|
281
|
+
{"model": "2960-24TT", "name": "SW1",
|
|
282
|
+
"config": ["hostname SW1", "vlan 10", "name USERS",
|
|
283
|
+
"interface FastEthernet0/1", "switchport mode access",
|
|
284
|
+
"switchport access vlan 10"]},
|
|
285
|
+
{"model": "PC-PT", "name": "PC0", "ipv4": "192.168.10.10/24,192.168.10.1"},
|
|
286
|
+
{"model": "PC-PT", "name": "PC1", "ipv4": "192.168.10.11/24,192.168.10.1"}
|
|
287
|
+
],
|
|
288
|
+
"links": [
|
|
289
|
+
{"from": "R1", "to": "SW1"},
|
|
290
|
+
{"from": "PC0", "to": "SW1"},
|
|
291
|
+
{"from": "PC1", "to": "SW1"}
|
|
292
|
+
]
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
```powershell
|
|
297
|
+
python -m ptforge build fixtures\specs\office_lan.json -o office_lan.pkt
|
|
298
|
+
python -m ptforge inspect office_lan.pkt
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
- 不写端口 → 自动找空闲口;不写 `cable` → 同类设备交叉线、异类直通线;不写坐标 → 自动布局。
|
|
302
|
+
- `ipv4` 支持 `"ip/prefix,gw"`、`"ip mask gw"`、`[ip, mask, gw]`、`{address, mask, gateway}`。
|
|
303
|
+
|
|
304
|
+
### 2. 离线验收
|
|
305
|
+
|
|
306
|
+
```powershell
|
|
307
|
+
python -m ptforge check office_lan.pkt --expect '[{"device":"R1","interface":"Gi0/0","ip":"192.168.10.1"}]'
|
|
308
|
+
python -m ptforge state office_lan.pkt
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### 3. 真机验收(可选)
|
|
312
|
+
|
|
313
|
+
先 `python -m ptforge open office_lan.pkt`,双击设备打开控制台,然后:
|
|
314
|
+
|
|
315
|
+
```powershell
|
|
316
|
+
python -m ptforge.guitool exec R1 "show ip route" --out route.png
|
|
317
|
+
python -m ptforge.guitool assert PC0 --checks '[{"command":"ipconfig","contains":"192.168.10.10"}]'
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### 4. 出报告素材
|
|
321
|
+
|
|
322
|
+
```powershell
|
|
323
|
+
python -m ptforge report office_lan.pkt -o report --title "实验室验收报告" `
|
|
324
|
+
--figure '{"path":"figures/topology.png","caption":"逻辑拓扑"}'
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
产出 `report/figures/`、`report/captions.json`、`report/report.md`。
|
|
328
|
+
|
|
329
|
+
---
|
|
330
|
+
|
|
331
|
+
## 工具参考
|
|
332
|
+
|
|
333
|
+
完整的参数、例子与流水线见 **[docs/TOOLS.md](docs/TOOLS.md)**。离线与运行时的分工:
|
|
334
|
+
|
|
335
|
+
| 类别 | 工具 |
|
|
336
|
+
| --- | --- |
|
|
337
|
+
| 构建 | `pt_models` `pt_build` `pt_open` |
|
|
338
|
+
| 修改 | `pt_patch` `pt_apply` `pt_note` `pt_server_page` |
|
|
339
|
+
| 读取 / 校验 | `pt_inspect` `pt_state` `pt_check` `pt_doctor` `pt_report` |
|
|
340
|
+
| 运行时 | `pt_gui` `pt_exec` `pt_assert` `pt_ping` `pt_http_get` `pt_ftp` |
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## 命令行
|
|
345
|
+
|
|
346
|
+
`python -m ptforge` 子命令:`models` `build` `inspect` `apply` `patch` `state` `check` `note` `web` `doctor` `report` `demo` `open`,全部支持 `--json`。
|
|
347
|
+
|
|
348
|
+
`python -m ptforge.guitool` 子命令:`focus` `click` `type` `key` `shot` `paste` `copy` `clipboard` `exec` `assert` `ping` `http` `ftp`。
|
|
349
|
+
|
|
350
|
+
---
|
|
351
|
+
|
|
352
|
+
## 验收与测试
|
|
353
|
+
|
|
354
|
+
```powershell
|
|
355
|
+
python -m unittest discover -s tests # 20 tests, OK
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
| 场景 | 结果 |
|
|
359
|
+
| --- | --- |
|
|
360
|
+
| 容器往返(真实 8.3.pkt,252 708 B) | 解密 → 重新加密 → PT 正常打开,22 台设备完整渲染 |
|
|
361
|
+
| 8.1.1 空骨架 | `fixtures/empty81.pkt` 34 234 B → 668 605 B XML,作为生成器基线 |
|
|
362
|
+
| 生成拓扑 + PT 重存 + 重开 | 通过(物理工作区节点、GUID 链、`FROM/PORT/TO/PORT` 顺序均已修正) |
|
|
363
|
+
| 端口命名 | 2911 `Gi0/0..0/2`、2960-24TT `FE0/1..0/24 + Gi0/1..0/2`、ISR4331 `Gi0/0/0..0/0/2`、PC-PT `FastEthernet0` |
|
|
364
|
+
| 命令行执行 | PC0 `ipconfig` 取回 305 字符;`ping 192.1.1.254` 回 4/4、0% 丢包 |
|
|
365
|
+
| 断言 | `show ip route` 命中 `O 192.1.3.0/24`、`[110/4] via 192.1.2.253`;故意断言不存在网段得到明确 FAIL |
|
|
366
|
+
| NAT 实验(`nat_lab.pkt`) | 6/6 离线断言 PASS;RIP 路由 `R 172.18.20.0 [120/2]`;静态 NAT `tcp 200.1.13.1:80 → 172.16.10.4:80`;PC4 访问 `http://200.1.13.1` 返回 Web1_Server 页面 |
|
|
367
|
+
|
|
368
|
+
---
|
|
369
|
+
|
|
370
|
+
## 已知边界
|
|
371
|
+
|
|
372
|
+
1. **没有官方 API**:运行时能力建立在窗口自动化上,要求 PT 窗口可见、可交互,且桌面前台可被抢占。
|
|
373
|
+
2. **终端只回读可见区域**:超长输出会滚出屏幕,`ftp`/长配置会保留会话中最长的一次快照;逐条命令建议加 `wait_ms`。
|
|
374
|
+
3. **同名设备歧义**:多个 PT 实例里存在同名设备时,需要先关闭重复实例或改名。
|
|
375
|
+
4. **文件版本**:只保证 `8.1.x`;其他版本的容器参数可能不同(`pt_doctor` 会先检查)。
|
|
376
|
+
5. **图形界面差异**:不同 PT 版本/缩放比例下,设备窗口内的相对坐标(标签页、URL 栏、Go 按钮)可能需要微调。
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## 目录结构
|
|
381
|
+
|
|
382
|
+
```
|
|
383
|
+
dsh-ptforge/
|
|
384
|
+
├── pyproject.toml # 打包元数据、入口点、包数据
|
|
385
|
+
├── Dockerfile # 离线引擎镜像(非 root、/work 卷)
|
|
386
|
+
├── docker-compose.yml # 一行式容器调用
|
|
387
|
+
├── .github/workflows/ # ci.yml(测试/打包/镜像)+ publish.yml(PyPI)
|
|
388
|
+
├── ptforge/ # 引擎(可独立作为 Python 包使用)
|
|
389
|
+
│ ├── ptcrypto/ # Twofish / CMAC / CTR / EAX / 容器格式
|
|
390
|
+
│ ├── assets/ # 8.1.1 骨架、80 个设备模板、端口命名表
|
|
391
|
+
│ ├── build.py # spec → ElementTree → .pkt
|
|
392
|
+
│ ├── state.py # 结构化状态与断言
|
|
393
|
+
│ ├── patch.py # 增量修改
|
|
394
|
+
│ ├── notes.py # 画布标注
|
|
395
|
+
│ ├── web.py # Server-PT 网页读写
|
|
396
|
+
│ ├── report.py # 报告素材
|
|
397
|
+
│ ├── gui.py / runtime.py # Win32 运行时
|
|
398
|
+
│ └── cli.py / guitool.py # 命令行入口
|
|
399
|
+
├── packages/dsh-ptforge/ # DSH bundle(含引擎副本)
|
|
400
|
+
├── docs/TOOLS.md # 18 个工具速查表
|
|
401
|
+
├── tests/ # 20 个单测
|
|
402
|
+
├── fixtures/ # 样例与 spec
|
|
403
|
+
├── LICENSE / NOTICE # MIT(本项目)与第三方代码范围说明
|
|
404
|
+
└── scripts/sync_engine.ps1 # 把引擎同步进 bundle
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
---
|
|
408
|
+
|
|
409
|
+
## 第三方代码
|
|
410
|
+
|
|
411
|
+
`ptforge/ptcrypto/twofish.py` 来自 [strykey/pka-decipher](https://github.com/strykey/pka-decipher),其内部保留了原始 Twofish 实现的版权声明(Gladman / Paulo S. L. M. Barreto)。`ptcrypto/` 下的 CMAC/CTR/EAX 与容器格式实现同样源自该仓库。
|
|
412
|
+
|
|
413
|
+
上游仓库未提供 LICENSE 文件;`LICENSE` 里的 MIT 只覆盖本项目自己写的代码,vendored 的密码学实现不在授权范围内(详见 [`NOTICE`](NOTICE))。如果你要商业分发或换许可证,请先用有明确授权的替代实现替换 `ptcrypto/`,或联系上游作者取得许可。
|
|
414
|
+
|
|
415
|
+
本项目与 Cisco 无关,Packet Tracer 是其商标;这里使用的 `.pkt` 容器格式与 IOS 命令语法均为未公开接口,仅用于教学/研究场景的互操作。
|
|
416
|
+
|
|
417
|
+
|