Add files via upload
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,121 @@
|
||||
"""
|
||||
思科设备接口配置模板
|
||||
支持配置接口IP、状态、带宽、描述等操作
|
||||
"""
|
||||
|
||||
def configure_interface_ip(interface: str, ip_address: str, subnet_mask: str) -> str:
|
||||
"""
|
||||
配置接口IP地址
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如 GigabitEthernet0/1
|
||||
ip_address: IP地址
|
||||
subnet_mask: 子网掩码
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"interface {interface}",
|
||||
f"ip address {ip_address} {subnet_mask}",
|
||||
"no shutdown",
|
||||
"exit",
|
||||
"end"
|
||||
]
|
||||
return "\n".join(commands)
|
||||
|
||||
def configure_interface_state(interface: str, state: str = "up") -> str:
|
||||
"""
|
||||
配置接口状态
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如 GigabitEthernet0/1
|
||||
state: 接口状态,up或down
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"interface {interface}"
|
||||
]
|
||||
|
||||
if state.lower() == "up":
|
||||
commands.append("no shutdown")
|
||||
elif state.lower() == "down":
|
||||
commands.append("shutdown")
|
||||
|
||||
commands.append("exit")
|
||||
commands.append("end")
|
||||
return "\n".join(commands)
|
||||
|
||||
def configure_interface_description(interface: str, description: str) -> str:
|
||||
"""
|
||||
配置接口描述
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如 GigabitEthernet0/1
|
||||
description: 接口描述
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"interface {interface}",
|
||||
f"description {description}",
|
||||
"exit",
|
||||
"end"
|
||||
]
|
||||
return "\n".join(commands)
|
||||
|
||||
def configure_interface_bandwidth(interface: str, bandwidth: str) -> str:
|
||||
"""
|
||||
配置接口带宽
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如 GigabitEthernet0/1
|
||||
bandwidth: 带宽,单位kbps
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"interface {interface}",
|
||||
f"bandwidth {bandwidth}",
|
||||
"exit",
|
||||
"end"
|
||||
]
|
||||
return "\n".join(commands)
|
||||
|
||||
def show_interface(interface: str = None) -> str:
|
||||
"""
|
||||
显示接口信息
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如GigabitEthernet0/1,为None时显示所有接口
|
||||
|
||||
Returns:
|
||||
显示命令字符串
|
||||
"""
|
||||
if interface:
|
||||
return f"show interface {interface}"
|
||||
else:
|
||||
return "show interface"
|
||||
|
||||
def show_ip_interface(interface: str = None) -> str:
|
||||
"""
|
||||
显示接口IP信息
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如GigabitEthernet0/1,为None时显示所有接口
|
||||
|
||||
Returns:
|
||||
显示命令字符串
|
||||
"""
|
||||
if interface:
|
||||
return f"show ip interface {interface}"
|
||||
else:
|
||||
return "show ip interface brief"
|
||||
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
思科设备的拓扑发现命令模板
|
||||
支持CDP和LLDP协议的邻居发现
|
||||
"""
|
||||
|
||||
def get_cdp_neighbors():
|
||||
"""获取CDP邻居列表"""
|
||||
return "show cdp neighbors"
|
||||
|
||||
def get_cdp_neighbors_detail():
|
||||
"""获取CDP邻居详细信息"""
|
||||
return "show cdp neighbors detail"
|
||||
|
||||
def get_lldp_neighbors():
|
||||
"""获取LLDP邻居列表"""
|
||||
return "show lldp neighbors"
|
||||
|
||||
def get_lldp_neighbors_detail():
|
||||
"""获取LLDP邻居详细信息"""
|
||||
return "show lldp neighbors detail"
|
||||
|
||||
def enable_cdp():
|
||||
"""全局启用CDP"""
|
||||
return "cdp run"
|
||||
|
||||
def enable_cdp_interface(interface: str):
|
||||
"""在指定接口启用CDP"""
|
||||
return f"""interface {interface}
|
||||
cdp enable
|
||||
exit"""
|
||||
|
||||
def enable_lldp():
|
||||
"""全局启用LLDP"""
|
||||
return """lldp run"""
|
||||
|
||||
def enable_lldp_interface(interface: str):
|
||||
"""在指定接口启用LLDP"""
|
||||
return f"""interface {interface}
|
||||
lldp transmit
|
||||
lldp receive
|
||||
exit"""
|
||||
|
||||
def get_interface_brief():
|
||||
"""获取接口简要信息"""
|
||||
return "show ip interface brief"
|
||||
|
||||
def get_interface_status():
|
||||
"""获取接口状态"""
|
||||
return "show interface status"
|
||||
|
||||
def get_interface_description():
|
||||
"""获取接口描述"""
|
||||
return "show interface description"
|
||||
|
||||
def get_cdp_interface(interface: str):
|
||||
"""获取指定接口的CDP信息"""
|
||||
return f"show cdp interface {interface}"
|
||||
|
||||
def get_lldp_interface(interface: str):
|
||||
"""获取指定接口的LLDP信息"""
|
||||
return f"show lldp interface {interface}"
|
||||
|
||||
def get_cdp_entry(device_name: str):
|
||||
"""获取特定设备的CDP条目"""
|
||||
return f"show cdp entry {device_name}"
|
||||
|
||||
def get_vlan_brief():
|
||||
"""获取VLAN简要信息(用于拓扑分析)"""
|
||||
return "show vlan brief"
|
||||
|
||||
def get_spanning_tree():
|
||||
"""获取生成树信息(用于拓扑分析)"""
|
||||
return "show spanning-tree"
|
||||
|
||||
def get_mac_address_table():
|
||||
"""获取MAC地址表(用于二层拓扑分析)"""
|
||||
return "show mac address-table"
|
||||
|
||||
def discover_full_topology():
|
||||
"""发现完整拓扑的命令序列"""
|
||||
commands = [
|
||||
"show cdp neighbors detail",
|
||||
"show lldp neighbors detail",
|
||||
"show ip interface brief",
|
||||
"show interface description",
|
||||
"show vlan brief"
|
||||
]
|
||||
return commands
|
||||
@@ -0,0 +1,94 @@
|
||||
"""
|
||||
思科设备VLAN配置模板
|
||||
支持创建VLAN、配置VLAN名称、将接口添加到VLAN等操作
|
||||
"""
|
||||
|
||||
def create_vlan(vlan_id: str, vlan_name: str = None) -> str:
|
||||
"""
|
||||
创建VLAN
|
||||
|
||||
Args:
|
||||
vlan_id: VLAN ID
|
||||
vlan_name: VLAN名称(可选)
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"vlan {vlan_id}"
|
||||
]
|
||||
|
||||
if vlan_name:
|
||||
commands.append(f"name {vlan_name}")
|
||||
|
||||
commands.append("exit")
|
||||
commands.append("end")
|
||||
return "\n".join(commands)
|
||||
|
||||
def add_interface_to_vlan(interface: str, vlan_id: str, mode: str = "access") -> str:
|
||||
"""
|
||||
将接口添加到VLAN
|
||||
|
||||
Args:
|
||||
interface: 接口名称,如 GigabitEthernet0/1
|
||||
vlan_id: VLAN ID
|
||||
mode: 接口模式,access或trunk
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"interface {interface}",
|
||||
"switchport"
|
||||
]
|
||||
|
||||
if mode.lower() == "access":
|
||||
commands.append("switchport mode access")
|
||||
commands.append(f"switchport access vlan {vlan_id}")
|
||||
elif mode.lower() == "trunk":
|
||||
commands.append("switchport mode trunk")
|
||||
commands.append(f"switchport trunk allowed vlan add {vlan_id}")
|
||||
|
||||
commands.append("exit")
|
||||
commands.append("end")
|
||||
return "\n".join(commands)
|
||||
|
||||
def delete_vlan(vlan_id: str) -> str:
|
||||
"""
|
||||
删除VLAN
|
||||
|
||||
Args:
|
||||
vlan_id: VLAN ID
|
||||
|
||||
Returns:
|
||||
配置命令字符串
|
||||
"""
|
||||
commands = [
|
||||
"configure terminal",
|
||||
f"no vlan {vlan_id}",
|
||||
"end"
|
||||
]
|
||||
return "\n".join(commands)
|
||||
|
||||
def show_vlan() -> str:
|
||||
"""
|
||||
显示VLAN信息
|
||||
|
||||
Returns:
|
||||
显示命令字符串
|
||||
"""
|
||||
return "show vlan brief"
|
||||
|
||||
def show_vlan_detail(vlan_id: str) -> str:
|
||||
"""
|
||||
显示特定VLAN的详细信息
|
||||
|
||||
Args:
|
||||
vlan_id: VLAN ID
|
||||
|
||||
Returns:
|
||||
显示命令字符串
|
||||
"""
|
||||
return f"show vlan id {vlan_id}"
|
||||
Reference in New Issue
Block a user