netmiko-ssh-automation
यह क्या करती है
यह टूल Python का इस्तेमाल करके राउटर और स्विच जैसे नेटवर्क डिवाइस पर काम अपने-आप करने में मदद करता है। इससे सुरक्षित तरीके से जानकारी इकट्ठा की जा सकती है या नियंत्रित कॉन्फ़िगरेशन बदलाव किए जा सकते हैं।
कब इस्तेमाल करें
- ✓कई डिवाइस से 'show' कमांड की जानकारी इकट्ठा करना।
- ✓नेटवर्क कॉन्फ़िगरेशन जांचने के लिए एक सरल स्क्रिप्ट बनाना।
- ✓नेटवर्क स्क्रिप्ट में सुरक्षा और एरर हैंडलिंग जोड़ना।
Skill का लिंक
https://github.com/affaan-m/ECC/blob/main/skills/netmiko-ssh-automation/SKILL.mdइसे कॉपी करके अपने AI (Claude, ChatGPT या Cursor) में पेस्ट करें और निर्देशों का पालन करने को कहें।
कैसे इस्तेमाल करें
सबसे आसान तरीका: मैसेज कॉपी करके अपने AI में पेस्ट करें। वह skill पढ़कर निर्देशों का पालन करेगा।
पेस्ट करने के लिए तैयार मैसेज
Claude Code, Codex या Cursor के लिए: प्रोजेक्ट फ़ोल्डर में चलाएँ और skill इंस्टॉल हो जाएगी।
SKILL.md डाउनलोड करें और अपने एजेंट के skills फ़ोल्डर में रखें।
AI से क्या माँगें: उदाहरण
“सभी राउटर से नेटवर्क इंटरफ़ेस की स्थिति इकट्ठा करो।”
हर हफ़्ते 5 नई skills, 1 मिनट में पढ़ें।
यह कैसे काम करती है
कोड SSH नाम के सुरक्षित प्रोटोकॉल से नेटवर्क डिवाइस से जुड़ता है, कमांड चलाता है, और जवाब को प्रोसेस कर सकता है। समस्याएं रोकने के लिए इसमें सुरक्षा उपाय भी शामिल हैं।
तकनीकी सामग्री (मूल SKILL.md)
लेखक का मूल टेक्स्ट, अंग्रेज़ी में, सीधे GitHub से।
Netmiko SSH Automation
Use this skill when writing or reviewing Python automation that connects to network devices with Netmiko. Keep the default path read-only; config changes need a separate change window, peer review, and rollback plan.
When to Use
- Collecting
showcommand output across routers, switches, or firewalls. - Building a small audit script for interface, routing, or config evidence.
- Adding timeouts and exception handling to network SSH scripts.
- Parsing command output with TextFSM when a template exists.
- Reviewing automation before it touches production devices.
Safety Defaults
- Start with read-only
send_command()collection. - Keep inventory small and explicit; do not sweep whole address ranges.
- Use environment variables, a vault, or
getpass; never hardcode credentials. - Set connection and read timeouts.
- Limit concurrency so older devices are not overloaded.
- Require an explicit operator flag before
send_config_set(). - Do not call
save_config()until the change has been verified and approved.
Read-Only Connection Pattern
import os
from getpass import getpass
from netmiko import ConnectHandler
from netmiko.exceptions import (
NetmikoAuthenticationException,
NetmikoTimeoutException,
ReadTimeout,
)
device = {
"device_type": "cisco_ios",
"host": "192.0.2.10",
"username": os.environ.get("NETMIKO_USERNAME") or input("Username: "),
"password": os.environ.get("NETMIKO_PASSWORD") or getpass("Password: "),
"secret": os.environ.get("NETMIKO_ENABLE_SECRET"),
"conn_timeout": 10,
"auth_timeout": 20,
"banner_timeout": 15,
"read_timeout_override": 30,
}
try:
with ConnectHandler(**device) as conn:
if device.get("secret") and not conn.check_enable_mode():
conn.enable()
output = conn.send_command("show ip interface brief", read_timeout=30)
print(output)
except NetmikoAuthenticationException:
print("Authentication failed")
except NetmikoTimeoutException:
print("SSH connection timed out")
except ReadTimeout:
print("Command read timed out")
Use placeholder addresses from documentation ranges in examples. Keep real inventory in an ignored local file or a secrets-managed system.
Batch Collection
from concurrent.futures import ThreadPoolExecutor, as_completed
from typing import Any
def collect_show(device: dict[str, Any], command: str) -> dict[str, Any]:
host = device["host"]
try:
with ConnectHandler(**device) as conn:
output = conn.send_command(command, read_timeout=45)
return {"host": host, "ok": True, "output": output}
except (NetmikoAuthenticationException, NetmikoTimeoutException, ReadTimeout) as exc:
return {"host": host, "ok": False, "error": type(exc).__name__}
results = []
with ThreadPoolExecutor(max_workers=8) as pool:
futures = [pool.submit(collect_show, device, "show version") for device in devices]
for future in as_completed(futures):
results.append(future.result())
Keep max_workers low unless the device estate and AAA systems are known to
handle higher connection volume.
Structured Parsing
Netmiko can ask TextFSM, TTP, or Genie to parse supported command output. Treat parser output as an optimization, not the only evidence path.
with ConnectHandler(**device) as conn:
parsed = conn.send_command(
"show ip interface brief",
use_textfsm=True,
raise_parsing_error=False,
read_timeout=30,
)
if isinstance(parsed, str):
print("No parser template matched; store raw output for review")
else:
for row in parsed:
print(row)
If parsing drives a blocking decision, keep the raw command output alongside the parsed result so an operator can inspect mismatches.
Guarded Config Pattern
import os
commands = [
"interface GigabitEthernet0/1",
"description CHANGE-1234 UPLINK-TO-CORE",
]
apply_changes = os.environ.get("APPLY_NETWORK_CHANGES") == "1"
if not apply_changes:
print("Dry run only. Candidate commands:")
print("\n".join(commands))
else:
with ConnectHandler(**device) as conn:
conn.enable()
before = conn.send_command("show running-config interface GigabitEthernet0/1")
output = conn.send_config_set(commands)
after = conn.send_command("show running-config interface GigabitEthernet0/1")
print(before)
print(output)
…
अक्सर पूछे जाने वाले सवाल
यह टूल पासवर्ड कैसे संभालता है?
यह एनवायरनमेंट वेरिएबल या प्रॉम्प्ट जैसे सुरक्षित तरीके इस्तेमाल करता है, और पासवर्ड को स्क्रिप्ट में कभी सीधे नहीं लिखता।
क्या मैं जोखिम वाले कॉन्फ़िगरेशन बदलाव कर सकता हूं?
हां, लेकिन बहुत सावधानी से। कॉन्फ़िगरेशन बदलावों के लिए एक अतिरिक्त पुष्टि और जांच का चरण ज़रूरी है, ताकि सुरक्षा बनी रहे।
अगर कनेक्शन फेल हो जाए तो क्या होगा?
यह टूल कनेक्शन या कमांड की गड़बड़ी को संभालने के लिए बना है। यह पूरी प्रक्रिया रोके बिना एरर बताता है।
जानकारी
लेखक का मूल विवरण
Safe Python Netmiko patterns for read-only collection, bounded batch SSH, TextFSM parsing, guarded config changes, timeouts, and network automation error handling. Use when automating network device access with Python Netmiko, whether collecting state or pushing guarded config changes.
repo: affaan-m/ECC
लोकप्रियता
- GitHub स्टार
- 280k
- रैंकिंग में स्थान
- #363
- लाइसेंस
- MIT
- अपडेट की गई
- 15/10/2026
कमेंट
- …
इस repository की और skills
accessibility
280kयह आपके एजेंट को ऐसे इंटरफ़ेस बनाने में मदद करता है जिन्हें हर कोई इस्तेमाल कर सके। यह पक्का करता है कि वेबसाइट और ऐप दिव्यांग लोगों के लिए भी अच्छे से काम करें, जैसे नेत्रहीन या जिन्हें चलने-फिरने में दिक्कत होती है।
agent-architecture-audit
280kयह आपके एजेंट को जाँचने देता है कि सब कुछ सही से चल रहा है। यह AI सिस्टम में समस्याएँ ढूँढकर ठीक करता है, ताकि वे उम्मीद के मुताबिक काम करें।
agent-eval
280kयह आपके एजेंट को अलग-अलग AI coding tools की तुलना करने में मदद करता है। यह मापता है कि किसी खास काम के लिए कौन सा टूल ज़्यादा तेज़, सस्ता और भरोसेमंद है।
agent-harness-construction
280kयह आपके एजेंट को काम कैसे करना है, यह बेहतर समझने में मदद करता है। यह उन tools और instructions को बेहतर बनाता है जिनका एजेंट इस्तेमाल करता है, ताकि उसकी सफलता की संभावना बढ़े।
मिलती-जुलती skills
shopify
260kआपके एजेंट को Shopify GraphQL API से स्टोर का डेटा पढ़ने और अपडेट करने देती है, जैसे उत्पाद, स्टॉक, ऑर्डर और ग्राहक।
rest-graphql-debug
260kआपके एजेंट को REST या GraphQL API कॉल क्यों विफल होती है, यह पता करने में मदद करती है, कनेक्शन, लॉगिन, अनुरोध फ़ॉर्मैट और जवाब को एक-एक परत करके जाँचते हुए।
har-derived-api-client
260kआपके एजेंट को किसी वेबसाइट के नेटवर्क ट्रैफ़िक को एक बार रिकॉर्ड करके सीधा API क्लाइंट बनाने देती है, ताकि हर बार पेज पर क्लिक करना न पड़े।