netcmd 1.2.0__tar.gz → 1.2.2__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.
- netcmd-1.2.2/PKG-INFO +188 -0
- netcmd-1.2.2/README.md +163 -0
- netcmd-1.2.2/netcmd.egg-info/PKG-INFO +188 -0
- {netcmd-1.2.0 → netcmd-1.2.2}/netcmd.py +235 -43
- {netcmd-1.2.0 → netcmd-1.2.2}/pyproject.toml +1 -1
- netcmd-1.2.2/tests/test_netcmd.py +188 -0
- netcmd-1.2.0/PKG-INFO +0 -149
- netcmd-1.2.0/README.md +0 -124
- netcmd-1.2.0/netcmd.egg-info/PKG-INFO +0 -149
- netcmd-1.2.0/tests/test_netcmd.py +0 -83
- {netcmd-1.2.0 → netcmd-1.2.2}/netcmd.egg-info/SOURCES.txt +0 -0
- {netcmd-1.2.0 → netcmd-1.2.2}/netcmd.egg-info/dependency_links.txt +0 -0
- {netcmd-1.2.0 → netcmd-1.2.2}/netcmd.egg-info/entry_points.txt +0 -0
- {netcmd-1.2.0 → netcmd-1.2.2}/netcmd.egg-info/requires.txt +0 -0
- {netcmd-1.2.0 → netcmd-1.2.2}/netcmd.egg-info/top_level.txt +0 -0
- {netcmd-1.2.0 → netcmd-1.2.2}/setup.cfg +0 -0
netcmd-1.2.2/PKG-INFO
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netcmd
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Multivendor SSH CLI command runner with parallel and interactive workflows
|
|
5
|
+
Author: jpesqueda
|
|
6
|
+
Project-URL: Homepage, https://github.com/jpesqueda/NetCmd
|
|
7
|
+
Project-URL: Repository, https://github.com/jpesqueda/NetCmd
|
|
8
|
+
Project-URL: Issues, https://github.com/jpesqueda/NetCmd/issues
|
|
9
|
+
Keywords: network automation,ssh,netmiko,cisco,arista,cli
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Networking
|
|
20
|
+
Classifier: Topic :: System :: Systems Administration
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: netmiko<5,>=4.3
|
|
24
|
+
Requires-Dist: rich<15,>=13.7
|
|
25
|
+
|
|
26
|
+
# NetCmd v1.2.2
|
|
27
|
+
|
|
28
|
+
Multivendor SSH command runner for Windows and other Python 3.10+ systems. Netmiko and Rich. Executes commands on individual devices or in parallel (20 workers by default). Supports Cisco IOS-XE, NX-OS, Arista EOS, and other Netmiko drivers. Command syntax is device-specific.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
py -m pip install -r requirements.txt
|
|
34
|
+
py netcmd.py --version
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For an installed PyPI distribution, `netcmd --version` uses the CLI entry point.
|
|
38
|
+
|
|
39
|
+
## Modes
|
|
40
|
+
|
|
41
|
+
```powershell
|
|
42
|
+
# Interactive wizard: host/host file, commands, username, password, suffix
|
|
43
|
+
netcmd
|
|
44
|
+
|
|
45
|
+
# Single host
|
|
46
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin -dt cisco_ios
|
|
47
|
+
|
|
48
|
+
# Multiple devices, identical commands
|
|
49
|
+
netcmd -hf hosts.txt -cf commands.txt -u admin -dt cisco_ios -w 20
|
|
50
|
+
|
|
51
|
+
# Multifile, device-specific commands
|
|
52
|
+
netcmd -mf multifile.txt -u admin -w 20
|
|
53
|
+
|
|
54
|
+
# SSH-only test: no commands and no result .txt files
|
|
55
|
+
netcmd -hf hosts.txt -u admin -dt cisco_ios --test-connection
|
|
56
|
+
|
|
57
|
+
# Alternate SSH port
|
|
58
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --port 2222
|
|
59
|
+
|
|
60
|
+
# OpenSSH config file (including compatible ProxyCommand setups)
|
|
61
|
+
netcmd -ho router-alias -cmd commands.txt -u admin --ssh-config ~/.ssh/config
|
|
62
|
+
|
|
63
|
+
# Explicit key verification with user's default known_hosts
|
|
64
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --strict-host-key
|
|
65
|
+
|
|
66
|
+
# Explicit custom known_hosts (combine with --strict-host-key to reject unknown keys)
|
|
67
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --known-hosts ~/.ssh/known_hosts --strict-host-key
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Use `-cmd`, `-cf`, or `--command-file` as synonyms. `--prefix`, `--suffix`, and `--timestamp` change **output filenames only**. `--verbose` prints device-level results as each worker finishes. Without `--verbose`, only connection failures appear per-device on screen.
|
|
71
|
+
|
|
72
|
+
### Multifile
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
HostName:SW01
|
|
76
|
+
DeviceType:cisco_ios
|
|
77
|
+
show version
|
|
78
|
+
show inventory
|
|
79
|
+
!
|
|
80
|
+
HostName:SW02
|
|
81
|
+
DeviceType:arista_eos
|
|
82
|
+
show version
|
|
83
|
+
show interfaces status
|
|
84
|
+
!
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Interactive command directives
|
|
88
|
+
|
|
89
|
+
The same parser works with `-cmd` and `-mf`:
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
@timeout 60
|
|
93
|
+
copy running-config startup-config
|
|
94
|
+
@expect Destination filename
|
|
95
|
+
@send [Enter]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Directives also include `@wait`, `@wait-disconnect`, and `@reconnect`. Always validate prompts and procedures on your hardware and firmware before disruptive execution. Timeouts do not guarantee that a command has finished safely.
|
|
99
|
+
|
|
100
|
+
## Output and logs
|
|
101
|
+
|
|
102
|
+
Result text files now resemble a live CLI session:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
SW01#show version
|
|
106
|
+
Cisco IOS XE Software ...
|
|
107
|
+
|
|
108
|
+
SW01#show module
|
|
109
|
+
Module Status
|
|
110
|
+
1 ok
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The prompt is read from the device's live CLI session rather than reconstructed from the input hostname. The capture removes only the first duplicated echo and a trailing standalone prompt; interactive prompts and CLI error text are preserved. If no CLI command has produced a response, **no empty TXT is written**.
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
Outputs/
|
|
117
|
+
├── Results/
|
|
118
|
+
│ ├── pre_SW01_checks_YYYYMMDD_HHMMSS.txt
|
|
119
|
+
│ └── pre_SW02_checks_YYYYMMDD_HHMMSS.txt
|
|
120
|
+
└── Logs/
|
|
121
|
+
├── NetCmd_YYYYMMDD_HHMMSS.log
|
|
122
|
+
└── Summary_YYYYMMDD_HHMMSS.log
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
No CSV or JSON reports are generated. `--test-connection` writes only logs, not result `.txt` files. At the end, the terminal shows a green `Status: All Success` when all devices succeeded; otherwise it shows red `Some Commands Failed` or `Some Devices Failed`. Authentication failure and unresolved hostnames are shown in the terminal even without verbose mode.
|
|
126
|
+
|
|
127
|
+
## Connection options
|
|
128
|
+
|
|
129
|
+
| Option | Purpose |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `--port` | Destination SSH port (default 22) |
|
|
132
|
+
| `--conn-timeout` | TCP/SSH connect timeout |
|
|
133
|
+
| `--timeout` | Per-command timeout |
|
|
134
|
+
| `-dt` | Netmiko device driver, otherwise SSH autodetection |
|
|
135
|
+
| `--ssh-config` | Path to OpenSSH config used by Netmiko (ProxyCommand support; compatibility depends on Netmiko) |
|
|
136
|
+
| `--known-hosts` | Load a custom host key file |
|
|
137
|
+
| `--strict-host-key` | Reject unknown/mismatched SSH server host keys |
|
|
138
|
+
| `--test-connection` | Check SSH connectivity and authentication only; no commands |
|
|
139
|
+
|
|
140
|
+
**Security:** Prefer entering the password through the secure prompt rather than `-p` on the command line. Avoid committing real configuration outputs, private hostnames or credentials to public repositories. A host-key check protects against connecting to an unexpected server; ensure you trust the key material.
|
|
141
|
+
|
|
142
|
+
## Local tests
|
|
143
|
+
|
|
144
|
+
```powershell
|
|
145
|
+
py -m unittest discover -s tests -v
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Offline tests cover command transcript formatting, error categorization, empty-output suppression, interactive prompting, and test-connection mode. Live SSH integration must still be tested against representative devices before any production change.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
## V1.2.2 — Automatic CLI Mode Tracking
|
|
152
|
+
|
|
153
|
+
A command file can represent a full Cisco-style session, including
|
|
154
|
+
config t, TACACS configuration submodes, exit, end, and wr. NetCmd
|
|
155
|
+
waits for the final complete prompt after each command; for Cisco/Arista
|
|
156
|
+
drivers it detects failed config t/end transitions. No extra CLI flags.
|
|
157
|
+
|
|
158
|
+
Example tacacs_config.txt (documentation-only addresses/keys):
|
|
159
|
+
|
|
160
|
+
```text
|
|
161
|
+
config t
|
|
162
|
+
tacacs server TACACS-NEW-01
|
|
163
|
+
address ipv4 192.0.2.10
|
|
164
|
+
key 0 REEMPLAZAR_CLAVE
|
|
165
|
+
exit
|
|
166
|
+
tacacs server TACACS-NEW-02
|
|
167
|
+
address ipv4 192.0.2.11
|
|
168
|
+
key 0 REEMPLAZAR_CLAVE
|
|
169
|
+
exit
|
|
170
|
+
aaa group server tacacs+ TACACS_NEW
|
|
171
|
+
server name TACACS-NEW-01
|
|
172
|
+
server name TACACS-NEW-02
|
|
173
|
+
exit
|
|
174
|
+
end
|
|
175
|
+
wr
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Run: `netcmd -hf hosts.txt -cmd tacacs_config.txt -u admin --suffix TACACS`
|
|
179
|
+
|
|
180
|
+
The default is mode exec, so the file itself should contain config t
|
|
181
|
+
when needed; do not also pass --mode config for this mixed file.
|
|
182
|
+
|
|
183
|
+
SAFETY: CLI result captures may expose secrets from commands.
|
|
184
|
+
Do not commit real TACACS keys or captured configuration outputs.
|
|
185
|
+
For AAA changes use a pilot switch, independent login verification,
|
|
186
|
+
out-of-band recovery and --on-error stop before changing a fleet.
|
|
187
|
+
Prompt recognition is best-effort on Cisco-like devices; device/firmware
|
|
188
|
+
behavior must be validated. This is not transactional rollback.
|
netcmd-1.2.2/README.md
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# NetCmd v1.2.2
|
|
2
|
+
|
|
3
|
+
Multivendor SSH command runner for Windows and other Python 3.10+ systems. Netmiko and Rich. Executes commands on individual devices or in parallel (20 workers by default). Supports Cisco IOS-XE, NX-OS, Arista EOS, and other Netmiko drivers. Command syntax is device-specific.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```powershell
|
|
8
|
+
py -m pip install -r requirements.txt
|
|
9
|
+
py netcmd.py --version
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
For an installed PyPI distribution, `netcmd --version` uses the CLI entry point.
|
|
13
|
+
|
|
14
|
+
## Modes
|
|
15
|
+
|
|
16
|
+
```powershell
|
|
17
|
+
# Interactive wizard: host/host file, commands, username, password, suffix
|
|
18
|
+
netcmd
|
|
19
|
+
|
|
20
|
+
# Single host
|
|
21
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin -dt cisco_ios
|
|
22
|
+
|
|
23
|
+
# Multiple devices, identical commands
|
|
24
|
+
netcmd -hf hosts.txt -cf commands.txt -u admin -dt cisco_ios -w 20
|
|
25
|
+
|
|
26
|
+
# Multifile, device-specific commands
|
|
27
|
+
netcmd -mf multifile.txt -u admin -w 20
|
|
28
|
+
|
|
29
|
+
# SSH-only test: no commands and no result .txt files
|
|
30
|
+
netcmd -hf hosts.txt -u admin -dt cisco_ios --test-connection
|
|
31
|
+
|
|
32
|
+
# Alternate SSH port
|
|
33
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --port 2222
|
|
34
|
+
|
|
35
|
+
# OpenSSH config file (including compatible ProxyCommand setups)
|
|
36
|
+
netcmd -ho router-alias -cmd commands.txt -u admin --ssh-config ~/.ssh/config
|
|
37
|
+
|
|
38
|
+
# Explicit key verification with user's default known_hosts
|
|
39
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --strict-host-key
|
|
40
|
+
|
|
41
|
+
# Explicit custom known_hosts (combine with --strict-host-key to reject unknown keys)
|
|
42
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --known-hosts ~/.ssh/known_hosts --strict-host-key
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Use `-cmd`, `-cf`, or `--command-file` as synonyms. `--prefix`, `--suffix`, and `--timestamp` change **output filenames only**. `--verbose` prints device-level results as each worker finishes. Without `--verbose`, only connection failures appear per-device on screen.
|
|
46
|
+
|
|
47
|
+
### Multifile
|
|
48
|
+
|
|
49
|
+
```text
|
|
50
|
+
HostName:SW01
|
|
51
|
+
DeviceType:cisco_ios
|
|
52
|
+
show version
|
|
53
|
+
show inventory
|
|
54
|
+
!
|
|
55
|
+
HostName:SW02
|
|
56
|
+
DeviceType:arista_eos
|
|
57
|
+
show version
|
|
58
|
+
show interfaces status
|
|
59
|
+
!
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Interactive command directives
|
|
63
|
+
|
|
64
|
+
The same parser works with `-cmd` and `-mf`:
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
@timeout 60
|
|
68
|
+
copy running-config startup-config
|
|
69
|
+
@expect Destination filename
|
|
70
|
+
@send [Enter]
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Directives also include `@wait`, `@wait-disconnect`, and `@reconnect`. Always validate prompts and procedures on your hardware and firmware before disruptive execution. Timeouts do not guarantee that a command has finished safely.
|
|
74
|
+
|
|
75
|
+
## Output and logs
|
|
76
|
+
|
|
77
|
+
Result text files now resemble a live CLI session:
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
SW01#show version
|
|
81
|
+
Cisco IOS XE Software ...
|
|
82
|
+
|
|
83
|
+
SW01#show module
|
|
84
|
+
Module Status
|
|
85
|
+
1 ok
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The prompt is read from the device's live CLI session rather than reconstructed from the input hostname. The capture removes only the first duplicated echo and a trailing standalone prompt; interactive prompts and CLI error text are preserved. If no CLI command has produced a response, **no empty TXT is written**.
|
|
89
|
+
|
|
90
|
+
```text
|
|
91
|
+
Outputs/
|
|
92
|
+
├── Results/
|
|
93
|
+
│ ├── pre_SW01_checks_YYYYMMDD_HHMMSS.txt
|
|
94
|
+
│ └── pre_SW02_checks_YYYYMMDD_HHMMSS.txt
|
|
95
|
+
└── Logs/
|
|
96
|
+
├── NetCmd_YYYYMMDD_HHMMSS.log
|
|
97
|
+
└── Summary_YYYYMMDD_HHMMSS.log
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
No CSV or JSON reports are generated. `--test-connection` writes only logs, not result `.txt` files. At the end, the terminal shows a green `Status: All Success` when all devices succeeded; otherwise it shows red `Some Commands Failed` or `Some Devices Failed`. Authentication failure and unresolved hostnames are shown in the terminal even without verbose mode.
|
|
101
|
+
|
|
102
|
+
## Connection options
|
|
103
|
+
|
|
104
|
+
| Option | Purpose |
|
|
105
|
+
|---|---|
|
|
106
|
+
| `--port` | Destination SSH port (default 22) |
|
|
107
|
+
| `--conn-timeout` | TCP/SSH connect timeout |
|
|
108
|
+
| `--timeout` | Per-command timeout |
|
|
109
|
+
| `-dt` | Netmiko device driver, otherwise SSH autodetection |
|
|
110
|
+
| `--ssh-config` | Path to OpenSSH config used by Netmiko (ProxyCommand support; compatibility depends on Netmiko) |
|
|
111
|
+
| `--known-hosts` | Load a custom host key file |
|
|
112
|
+
| `--strict-host-key` | Reject unknown/mismatched SSH server host keys |
|
|
113
|
+
| `--test-connection` | Check SSH connectivity and authentication only; no commands |
|
|
114
|
+
|
|
115
|
+
**Security:** Prefer entering the password through the secure prompt rather than `-p` on the command line. Avoid committing real configuration outputs, private hostnames or credentials to public repositories. A host-key check protects against connecting to an unexpected server; ensure you trust the key material.
|
|
116
|
+
|
|
117
|
+
## Local tests
|
|
118
|
+
|
|
119
|
+
```powershell
|
|
120
|
+
py -m unittest discover -s tests -v
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Offline tests cover command transcript formatting, error categorization, empty-output suppression, interactive prompting, and test-connection mode. Live SSH integration must still be tested against representative devices before any production change.
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
## V1.2.2 — Automatic CLI Mode Tracking
|
|
127
|
+
|
|
128
|
+
A command file can represent a full Cisco-style session, including
|
|
129
|
+
config t, TACACS configuration submodes, exit, end, and wr. NetCmd
|
|
130
|
+
waits for the final complete prompt after each command; for Cisco/Arista
|
|
131
|
+
drivers it detects failed config t/end transitions. No extra CLI flags.
|
|
132
|
+
|
|
133
|
+
Example tacacs_config.txt (documentation-only addresses/keys):
|
|
134
|
+
|
|
135
|
+
```text
|
|
136
|
+
config t
|
|
137
|
+
tacacs server TACACS-NEW-01
|
|
138
|
+
address ipv4 192.0.2.10
|
|
139
|
+
key 0 REEMPLAZAR_CLAVE
|
|
140
|
+
exit
|
|
141
|
+
tacacs server TACACS-NEW-02
|
|
142
|
+
address ipv4 192.0.2.11
|
|
143
|
+
key 0 REEMPLAZAR_CLAVE
|
|
144
|
+
exit
|
|
145
|
+
aaa group server tacacs+ TACACS_NEW
|
|
146
|
+
server name TACACS-NEW-01
|
|
147
|
+
server name TACACS-NEW-02
|
|
148
|
+
exit
|
|
149
|
+
end
|
|
150
|
+
wr
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Run: `netcmd -hf hosts.txt -cmd tacacs_config.txt -u admin --suffix TACACS`
|
|
154
|
+
|
|
155
|
+
The default is mode exec, so the file itself should contain config t
|
|
156
|
+
when needed; do not also pass --mode config for this mixed file.
|
|
157
|
+
|
|
158
|
+
SAFETY: CLI result captures may expose secrets from commands.
|
|
159
|
+
Do not commit real TACACS keys or captured configuration outputs.
|
|
160
|
+
For AAA changes use a pilot switch, independent login verification,
|
|
161
|
+
out-of-band recovery and --on-error stop before changing a fleet.
|
|
162
|
+
Prompt recognition is best-effort on Cisco-like devices; device/firmware
|
|
163
|
+
behavior must be validated. This is not transactional rollback.
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: netcmd
|
|
3
|
+
Version: 1.2.2
|
|
4
|
+
Summary: Multivendor SSH CLI command runner with parallel and interactive workflows
|
|
5
|
+
Author: jpesqueda
|
|
6
|
+
Project-URL: Homepage, https://github.com/jpesqueda/NetCmd
|
|
7
|
+
Project-URL: Repository, https://github.com/jpesqueda/NetCmd
|
|
8
|
+
Project-URL: Issues, https://github.com/jpesqueda/NetCmd/issues
|
|
9
|
+
Keywords: network automation,ssh,netmiko,cisco,arista,cli
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Topic :: System :: Networking
|
|
20
|
+
Classifier: Topic :: System :: Systems Administration
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
Requires-Dist: netmiko<5,>=4.3
|
|
24
|
+
Requires-Dist: rich<15,>=13.7
|
|
25
|
+
|
|
26
|
+
# NetCmd v1.2.2
|
|
27
|
+
|
|
28
|
+
Multivendor SSH command runner for Windows and other Python 3.10+ systems. Netmiko and Rich. Executes commands on individual devices or in parallel (20 workers by default). Supports Cisco IOS-XE, NX-OS, Arista EOS, and other Netmiko drivers. Command syntax is device-specific.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
```powershell
|
|
33
|
+
py -m pip install -r requirements.txt
|
|
34
|
+
py netcmd.py --version
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
For an installed PyPI distribution, `netcmd --version` uses the CLI entry point.
|
|
38
|
+
|
|
39
|
+
## Modes
|
|
40
|
+
|
|
41
|
+
```powershell
|
|
42
|
+
# Interactive wizard: host/host file, commands, username, password, suffix
|
|
43
|
+
netcmd
|
|
44
|
+
|
|
45
|
+
# Single host
|
|
46
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin -dt cisco_ios
|
|
47
|
+
|
|
48
|
+
# Multiple devices, identical commands
|
|
49
|
+
netcmd -hf hosts.txt -cf commands.txt -u admin -dt cisco_ios -w 20
|
|
50
|
+
|
|
51
|
+
# Multifile, device-specific commands
|
|
52
|
+
netcmd -mf multifile.txt -u admin -w 20
|
|
53
|
+
|
|
54
|
+
# SSH-only test: no commands and no result .txt files
|
|
55
|
+
netcmd -hf hosts.txt -u admin -dt cisco_ios --test-connection
|
|
56
|
+
|
|
57
|
+
# Alternate SSH port
|
|
58
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --port 2222
|
|
59
|
+
|
|
60
|
+
# OpenSSH config file (including compatible ProxyCommand setups)
|
|
61
|
+
netcmd -ho router-alias -cmd commands.txt -u admin --ssh-config ~/.ssh/config
|
|
62
|
+
|
|
63
|
+
# Explicit key verification with user's default known_hosts
|
|
64
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --strict-host-key
|
|
65
|
+
|
|
66
|
+
# Explicit custom known_hosts (combine with --strict-host-key to reject unknown keys)
|
|
67
|
+
netcmd -ho 192.0.2.10 -cmd commands.txt -u admin --known-hosts ~/.ssh/known_hosts --strict-host-key
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Use `-cmd`, `-cf`, or `--command-file` as synonyms. `--prefix`, `--suffix`, and `--timestamp` change **output filenames only**. `--verbose` prints device-level results as each worker finishes. Without `--verbose`, only connection failures appear per-device on screen.
|
|
71
|
+
|
|
72
|
+
### Multifile
|
|
73
|
+
|
|
74
|
+
```text
|
|
75
|
+
HostName:SW01
|
|
76
|
+
DeviceType:cisco_ios
|
|
77
|
+
show version
|
|
78
|
+
show inventory
|
|
79
|
+
!
|
|
80
|
+
HostName:SW02
|
|
81
|
+
DeviceType:arista_eos
|
|
82
|
+
show version
|
|
83
|
+
show interfaces status
|
|
84
|
+
!
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Interactive command directives
|
|
88
|
+
|
|
89
|
+
The same parser works with `-cmd` and `-mf`:
|
|
90
|
+
|
|
91
|
+
```text
|
|
92
|
+
@timeout 60
|
|
93
|
+
copy running-config startup-config
|
|
94
|
+
@expect Destination filename
|
|
95
|
+
@send [Enter]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Directives also include `@wait`, `@wait-disconnect`, and `@reconnect`. Always validate prompts and procedures on your hardware and firmware before disruptive execution. Timeouts do not guarantee that a command has finished safely.
|
|
99
|
+
|
|
100
|
+
## Output and logs
|
|
101
|
+
|
|
102
|
+
Result text files now resemble a live CLI session:
|
|
103
|
+
|
|
104
|
+
```text
|
|
105
|
+
SW01#show version
|
|
106
|
+
Cisco IOS XE Software ...
|
|
107
|
+
|
|
108
|
+
SW01#show module
|
|
109
|
+
Module Status
|
|
110
|
+
1 ok
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The prompt is read from the device's live CLI session rather than reconstructed from the input hostname. The capture removes only the first duplicated echo and a trailing standalone prompt; interactive prompts and CLI error text are preserved. If no CLI command has produced a response, **no empty TXT is written**.
|
|
114
|
+
|
|
115
|
+
```text
|
|
116
|
+
Outputs/
|
|
117
|
+
├── Results/
|
|
118
|
+
│ ├── pre_SW01_checks_YYYYMMDD_HHMMSS.txt
|
|
119
|
+
│ └── pre_SW02_checks_YYYYMMDD_HHMMSS.txt
|
|
120
|
+
└── Logs/
|
|
121
|
+
├── NetCmd_YYYYMMDD_HHMMSS.log
|
|
122
|
+
└── Summary_YYYYMMDD_HHMMSS.log
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
No CSV or JSON reports are generated. `--test-connection` writes only logs, not result `.txt` files. At the end, the terminal shows a green `Status: All Success` when all devices succeeded; otherwise it shows red `Some Commands Failed` or `Some Devices Failed`. Authentication failure and unresolved hostnames are shown in the terminal even without verbose mode.
|
|
126
|
+
|
|
127
|
+
## Connection options
|
|
128
|
+
|
|
129
|
+
| Option | Purpose |
|
|
130
|
+
|---|---|
|
|
131
|
+
| `--port` | Destination SSH port (default 22) |
|
|
132
|
+
| `--conn-timeout` | TCP/SSH connect timeout |
|
|
133
|
+
| `--timeout` | Per-command timeout |
|
|
134
|
+
| `-dt` | Netmiko device driver, otherwise SSH autodetection |
|
|
135
|
+
| `--ssh-config` | Path to OpenSSH config used by Netmiko (ProxyCommand support; compatibility depends on Netmiko) |
|
|
136
|
+
| `--known-hosts` | Load a custom host key file |
|
|
137
|
+
| `--strict-host-key` | Reject unknown/mismatched SSH server host keys |
|
|
138
|
+
| `--test-connection` | Check SSH connectivity and authentication only; no commands |
|
|
139
|
+
|
|
140
|
+
**Security:** Prefer entering the password through the secure prompt rather than `-p` on the command line. Avoid committing real configuration outputs, private hostnames or credentials to public repositories. A host-key check protects against connecting to an unexpected server; ensure you trust the key material.
|
|
141
|
+
|
|
142
|
+
## Local tests
|
|
143
|
+
|
|
144
|
+
```powershell
|
|
145
|
+
py -m unittest discover -s tests -v
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Offline tests cover command transcript formatting, error categorization, empty-output suppression, interactive prompting, and test-connection mode. Live SSH integration must still be tested against representative devices before any production change.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
## V1.2.2 — Automatic CLI Mode Tracking
|
|
152
|
+
|
|
153
|
+
A command file can represent a full Cisco-style session, including
|
|
154
|
+
config t, TACACS configuration submodes, exit, end, and wr. NetCmd
|
|
155
|
+
waits for the final complete prompt after each command; for Cisco/Arista
|
|
156
|
+
drivers it detects failed config t/end transitions. No extra CLI flags.
|
|
157
|
+
|
|
158
|
+
Example tacacs_config.txt (documentation-only addresses/keys):
|
|
159
|
+
|
|
160
|
+
```text
|
|
161
|
+
config t
|
|
162
|
+
tacacs server TACACS-NEW-01
|
|
163
|
+
address ipv4 192.0.2.10
|
|
164
|
+
key 0 REEMPLAZAR_CLAVE
|
|
165
|
+
exit
|
|
166
|
+
tacacs server TACACS-NEW-02
|
|
167
|
+
address ipv4 192.0.2.11
|
|
168
|
+
key 0 REEMPLAZAR_CLAVE
|
|
169
|
+
exit
|
|
170
|
+
aaa group server tacacs+ TACACS_NEW
|
|
171
|
+
server name TACACS-NEW-01
|
|
172
|
+
server name TACACS-NEW-02
|
|
173
|
+
exit
|
|
174
|
+
end
|
|
175
|
+
wr
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Run: `netcmd -hf hosts.txt -cmd tacacs_config.txt -u admin --suffix TACACS`
|
|
179
|
+
|
|
180
|
+
The default is mode exec, so the file itself should contain config t
|
|
181
|
+
when needed; do not also pass --mode config for this mixed file.
|
|
182
|
+
|
|
183
|
+
SAFETY: CLI result captures may expose secrets from commands.
|
|
184
|
+
Do not commit real TACACS keys or captured configuration outputs.
|
|
185
|
+
For AAA changes use a pilot switch, independent login verification,
|
|
186
|
+
out-of-band recovery and --on-error stop before changing a fleet.
|
|
187
|
+
Prompt recognition is best-effort on Cisco-like devices; device/firmware
|
|
188
|
+
behavior must be validated. This is not transactional rollback.
|