Feat: 添加详细的MAC地址解析调试日志
- 输出邻居MAC解析详情 - 输出每个接口的MAC地址状态 - 输出收集的MAC地址总数 - 帮助诊断为什么MAC地址为空
Esse commit está contido em:
@@ -47,11 +47,14 @@ func (p *H3CParser) Parse(device *models.Device, outputs []string) error {
|
|||||||
for _, iface := range device.Interfaces {
|
for _, iface := range device.Interfaces {
|
||||||
if iface.MAC != "" {
|
if iface.MAC != "" {
|
||||||
macSet[iface.MAC] = true
|
macSet[iface.MAC] = true
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" Interface %s has no MAC address\n", iface.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for mac := range macSet {
|
for mac := range macSet {
|
||||||
device.MACAddresses = append(device.MACAddresses, mac)
|
device.MACAddresses = append(device.MACAddresses, mac)
|
||||||
}
|
}
|
||||||
|
fmt.Printf(" Collected %d unique MAC addresses for device %s\n", len(macSet), device.IP)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析ARP表用于MAC到IP映射(允许失败)
|
// 解析ARP表用于MAC到IP映射(允许失败)
|
||||||
@@ -289,6 +292,7 @@ func (p *H3CParser) parseNeighbors(output string, arpTable map[string]string) []
|
|||||||
mac := strings.TrimSpace(strings.ToLower(macParts[0]))
|
mac := strings.TrimSpace(strings.ToLower(macParts[0]))
|
||||||
// 保存MAC地址
|
// 保存MAC地址
|
||||||
currentNeighbor.RemoteMAC = mac
|
currentNeighbor.RemoteMAC = mac
|
||||||
|
fmt.Printf(" Parsed neighbor MAC: %s (from line: %s)\n", mac, line)
|
||||||
|
|
||||||
// 通过ARP表查找IP(如果有)
|
// 通过ARP表查找IP(如果有)
|
||||||
if ip, ok := arpTable[mac]; ok {
|
if ip, ok := arpTable[mac]; ok {
|
||||||
@@ -298,7 +302,11 @@ func (p *H3CParser) parseNeighbors(output string, arpTable map[string]string) []
|
|||||||
// 如果ARP表中没有,使用MAC地址作为标识(但RemoteIP仍为空)
|
// 如果ARP表中没有,使用MAC地址作为标识(但RemoteIP仍为空)
|
||||||
currentNeighbor.RemoteDevice = mac
|
currentNeighbor.RemoteDevice = mac
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" WARNING: Could not parse MAC from ChassisID line: %s\n", line)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf(" WARNING: ChassisID line has no colon: %s\n", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Referência em uma Nova Issue
Bloquear um usuário