From db161fa3f20c9f197db8fbdd8ff2484e499cbe3e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 26 Apr 2026 03:06:15 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20=E4=BD=BF=E7=94=A8display=20interface=20?= =?UTF-8?q?brief=E6=9B=BF=E4=BB=A3ip=20interface=20brief?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 交换机使用VLAN互联,应该使用display interface brief - 移除ARP表依赖,直接使用LLDP邻居信息 - 简化命令列表从6个减少到5个 --- internal/device/h3c.go | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/internal/device/h3c.go b/internal/device/h3c.go index 887cd9b..9c4bff4 100644 --- a/internal/device/h3c.go +++ b/internal/device/h3c.go @@ -19,20 +19,18 @@ func (p *H3CParser) GetCommands() []string { "screen-length disable", // 禁用分页(H3C/华为设备必需) "display version", "display interface", - "display ip interface brief", + "display interface brief", // 接口简要信息(包含VLAN和物理接口状态) "display lldp neighbor-information", - "display arp", // ARP表用于MAC到IP的映射 } } // Parse 解析H3C设备输出 func (p *H3CParser) Parse(device *models.Device, outputs []string) error { - if len(outputs) < 6 { + if len(outputs) < 5 { return fmt.Errorf("insufficient command outputs") } // outputs[0] 是 screen-length disable 的输出(通常为空) - fmt.Printf("[H3C DEBUG] screen-length disable output: %q (length: %d)\n", outputs[0], len(outputs[0])) p.parseVersion(device, outputs[1]) // outputs[1] 是 display version // outputs[2] 是 display interface @@ -51,7 +49,8 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error { if outputs[2] == "" { fmt.Printf("Warning: 'display interface' output is empty for device %s\n", device.IP) } else { - device.Interfaces = p.parseInterfaces(outputs[2], outputs[3]) // outputs[3] 是 display ip interface brief + // outputs[3] 是 display interface brief + device.Interfaces = p.parseInterfaces(outputs[2], outputs[3]) if len(device.Interfaces) == 0 { fmt.Printf("Warning: parsed 0 interfaces for device %s (output length: %d)\n", device.IP, len(outputs[2])) @@ -73,24 +72,12 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error { } // outputs[4] 是 display lldp neighbor-information - // outputs[5] 是 display arp - // 解析ARP表用于MAC到IP映射(允许失败) - arpTable := make(map[string]string) - if outputs[5] != "" { - arpTable = p.parseARPTable(outputs[5]) - if len(arpTable) == 0 { - fmt.Printf("Warning: ARP table is empty for device %s\n", device.IP) - } - } else { - fmt.Printf("Warning: ARP command output is empty for device %s\n", device.IP) - } + // 解析LLDP邻居 + device.Neighbors = p.parseNeighbors(outputs[4], nil) - // 解析LLDP邻居,使用ARP表进行MAC到IP的映射 - device.Neighbors = p.parseNeighbors(outputs[4], arpTable) - - fmt.Printf("Device %s: %d interfaces, %d neighbors, %d ARP entries\n", - device.IP, len(device.Interfaces), len(device.Neighbors), len(arpTable)) + fmt.Printf("Device %s: %d interfaces, %d neighbors\n", + device.IP, len(device.Interfaces), len(device.Neighbors)) return nil }