diff --git a/internal/device/h3c.go b/internal/device/h3c.go index aefc3c1..7fc840f 100644 --- a/internal/device/h3c.go +++ b/internal/device/h3c.go @@ -20,7 +20,7 @@ func (p *H3CParser) GetCommands() []string { "display interface", "display ip interface brief", "display lldp neighbor-information", - "display arp", // 添加ARP表用于MAC到IP的映射 + "display arp", // ARP表用于MAC到IP的映射 } } @@ -33,11 +33,22 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error { p.parseVersion(device, outputs[0]) device.Interfaces = p.parseInterfaces(outputs[1], outputs[2]) - // 解析ARP表用于MAC到IP映射 - arpTable := p.parseARPTable(outputs[4]) + // 解析ARP表用于MAC到IP映射(允许失败) + arpTable := make(map[string]string) + if outputs[4] != "" { + arpTable = p.parseARPTable(outputs[4]) + 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邻居,使用ARP表进行MAC到IP的映射 device.Neighbors = p.parseNeighbors(outputs[3], arpTable) + + fmt.Printf("Device %s: %d interfaces, %d neighbors, %d ARP entries\n", + device.IP, len(device.Interfaces), len(device.Neighbors), len(arpTable)) return nil } @@ -205,7 +216,11 @@ func (p *H3CParser) parseNeighbors(output string, arpTable map[string]string) [] // 通过ARP表查找IP if ip, ok := arpTable[mac]; ok { currentNeighbor.RemoteIP = ip - currentNeighbor.RemoteDevice = ip // 暂时用IP作为设备名 + currentNeighbor.RemoteDevice = ip + } else { + // 如果ARP表中没有,使用MAC地址作为标识 + currentNeighbor.RemoteDevice = mac + // 注意:RemoteIP为空,拓扑可能无法连线 } } }