Communitygithub.com

网络配置验证

在路由器或交换机配置部署前进行预检查,包括危险命令、重复地址、子网重叠、无效引用、管理平面风险以及IOS风格的安全卫生检查。

网络配置验证 是什么?

该技能用于在变更窗口或自动化任务触及生产设备之前,对网络配置进行全面的预检审核。它主要针对Cisco IOS/IOS-XE风格的配置片段,通过分层验证的方式发现危险命令(如reload、erase、format)、重复IP地址、子网重叠、未定义的ACL或路由映射引用、管理平面暴露风险(如VTY允许Telnet、缺少访问控制)以及安全卫生问题(如SNMP默认团体、SSH v1、enable password)。技能提供了基于Python的正则表达式检测脚本,能够解析接口IP地址并利用ipaddress库进行子网重叠计算,同时通过块解析方式避免VTY检查跨段误报。此技能适用于工程师手动审核或作为自动化流水线的阻塞门禁,但明确指出最终批准仍需人工审核意图、平台语法和回滚步骤。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/network-config-validation

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

网络配置验证 是做什么的?

在变更窗口或自动化任务触及生产设备之前,使用此技能审核网络配置。

何时使用

  • 部署前审核 Cisco IOS 或 IOS-XE 风格配置片段。
  • 审计脚本或模板生成的配置。
  • 查找危险命令、重复 IP 地址或子网重叠。
  • 检查 ACL、route-map、prefix-list 或线路策略是否被引用但未定义。
  • 为网络自动化构建轻量级预检脚本。

工作原理

将配置验证视为分层证据,而非完整的解析器。正则检查对预检警告有用,但最终批准仍需要网络工程师审核意图、平台语法和回滚步骤。

按以下顺序验证:

  1. 危险命令。
  2. 凭据和管理平面暴露。
  3. 重复地址和子网重叠。
  4. 对 ACL、route-map、prefix-list 和接口的无效引用。
  5. 操作卫生,如 NTP、时间戳、远程日志记录和横幅。

危险命令检测

import re

DANGEROUS_PATTERNS: list[tuple[re.Pattern[str], str]] = [
    (re.compile(r"\breload\b", re.I), "reload causes downtime"),
    (re.compile(r"\berase\s+(startup|nvram|flash)", re.I), "erases persistent storage"),
    (re.compile(r"\bformat\b", re.I), "formats a device filesystem"),
    (re.compile(r"\bno\s+router\s+(bgp|ospf|eigrp)\b", re.I), "removes a routing process"),
    (re.compile(r"\bno\s+interface\s+\S+", re.I), "removes interface configuration"),
    (re.compile(r"\baaa\s+new-model\b", re.I), "changes authentication behavior"),
    (re.compile(r"\bcrypto\s+key\s+(zeroize|generate)\b", re.I), "changes device SSH keys"),
]

def find_dangerous_commands(lines: list[str]) -> list[dict[str, str | int]]:
    findings = []
    for line_number, line in enumerate(lines, start=1):
        stripped = line.strip()
        for pattern, reason in DANGEROUS_PATTERNS:
            if pattern.search(stripped):
                findings.append({
                    "line": line_number,
                    "command": stripped,
                    "reason": reason,
                })
    return findings

重复 IP 和子网重叠

import ipaddress
import re
from collections import Counter

IP_ADDRESS_RE = re.compile(
    r"^\s*ip address\s+"
    r"(?P<ip>\d{1,3}(?:\.\d{1,3}){3})\s+"
    r"(?P<mask>\d{1,3}(?:\.\d{1,3}){3})\b",
    re.I | re.M,
)

def extract_interfaces(config: str) -> list[dict[str, str]]:
    results = []
    current = None
    for line in config.splitlines():
        if line.startswith("interface "):
            current = line.split(maxsplit=1)[1]
            continue
        match = IP_ADDRESS_RE.match(line)
        if current and match:
            ip = match.group("ip")
            mask = match.group("mask")
            network = ipaddress.ip_interface(f"{ip}/{mask}").network
            results.append({"interface": current, "ip": ip, "network": str(network)})
    return results

def find_duplicate_ips(config: str) -> list[str]:
    ips = [entry["ip"] for entry in extract_interfaces(config)]
    counts = Counter(ips)
    return sorted(ip for ip, count in counts.items() if count > 1)

def find_subnet_overlaps(config: str) -> list[tuple[str, str]]:
    networks = [ipaddress.ip_network(entry["network"]) for entry in extract_interfaces(config)]
    overlaps = []
    for index, left in enumerate(networks):
        for right in networks[index + 1:]:
            if left.overlaps(right):
                overlaps.append((str(left), str(right)))
    return overlaps

管理平面检查

按区域解析 VTY 块,避免访问类检查泄漏到无关行。

import re

def iter_blocks(config: str, starts_with: str) -> list[str]:
    blocks = []
    current: list[str] = []
    for line in config.splitlines():
        if line.startswith(starts_with):
            if current:
                blocks.append("\n".join(current))
            current = [line]
            continue
        if current:
            if line and not line.startswith(" "):
                blocks.append("\n".join(current))
                current = []
            else:
                current.append(line)
    if current:
        blocks.append("\n".join(current))
    return blocks

def check_vty_blocks(config: str) -> list[str]:
    issues = []
    for block in iter_blocks(config, "line vty"):
        if re.search(r"transport\s+input\s+.*telnet", block, re.I):
            issues.append("VTY 允许 Telnet;仅需 SSH。")
        if not re.search(r"\baccess-class\s+\S+\s+in\b", block, re.I):
            issues.append("VTY 块没有入站 access-class 源限制。")
        if not re.search(r"\bexec-timeout\s+\d+\s+\d+\b", block, re.I):
            issues.append("VTY 块没有显式的 exec-timeout。")
    return issues

安全卫生检查

SECURITY_PATTERNS = [
    (re.compile(r"\bsnmp-server community\s+(public|private)\b", re.I),
     "配置了默认 SNMP 团体"),
    (re.compile(r"\bsnmp-server community\s+\S+", re.I),
     "配置了 SNMPv2 团体字符串;推荐使用 SNMPv3 authPriv"),
    (re.compile(r"\bip ssh version 1\b", re.I),
     "启用了 SSH 版本 1"),
    (re.compile(r"\benable password\b", re.I),
     "存在 enable password;应使用 enable secret"),
    (re.compile(r"\busername\s+\S+\s+password\b", re.I),
     "本地用户名使用 password 而非 secret"),
]

BEST_PRACTICE_PATTERNS = [
    (re.compile(r"\bntp server\b", re.I), "NTP 服务器"),
    (re.compile(r"\bservice timestamps\b", re.I), "日志时间戳"),
    (re.compile(r"\blogging\s+\S+", re.I), "日志目的地或缓冲区"),
    (re.compile(r"\bsnmp-server group\s+\S+\s+v3\s+priv\b", re.I), "SNMPv3 authPriv 组"),
    (re.compile(r"\bbanner\s+(login|motd)\b", re.I), "登录横幅"),
]

def check_security(config: str) -> list[str]:
    return [message for pattern, message in SECURITY_PATTERNS if pattern.search(config)]

def check_missing_hygiene(config: str) -> list[str]:
    return [
        f"缺少 {description}"
        for pattern, description in BEST_PRACTICE_PATTERNS
        if not pattern.search(config)
    ]

示例

变更窗口预检

  1. 对即将粘贴的确切片段运行危险命令检查。
  2. 对完整候选配置运行重复 IP 和子网重叠检查。
  3. 确认每个引用的 ACL、route-map 和 prefix-list 都存在。
  4. 在进行任何管理平面更改之前,确认回滚命令和带外访问。

自动化预检

在 Netmiko、NAPALM、Ansible 或厂商 API 自动化推送生成的配置之前,使用验证作为阻塞门禁。对于危险命令和凭据,失败关闭。对于变更范围之外的最佳实践差距,发出警告。

反模式

  • 将正则验证视为设备解析器。
  • 未进行 dry-run 差异比较就直接应用生成的配置。
  • 将 SNMPv2 团体字符串推荐为监控需求。
  • 使用可能意外跨越无关区域的正则检查 VTY 块。
  • 通过禁用 ACL 而不是读取计数器/日志来测试防火墙行为。

参见

  • Agent: network-config-reviewer
  • Agent: network-troubleshooter
  • Skill: network-interface-health

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能