Created
November 21, 2021 21:39
-
-
Save ilyaevseev/26ea15eb94cefa8fd622dde15ffaeffa to your computer and use it in GitHub Desktop.
Find MAC address dups in Proxmox environment, happen after VM/CT cloning
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# string samples: | |
# /etc/pve/nodes/node1/lxc/123.conf:net0: name=eth0,bridge=vmbr0,firewall=1,gw=10.20.30.1,hwaddr=1A:2A:3A:CC:C0:0A,ip=10.20.30.40/24,type=veth | |
# /etc/pve/nodes/pm8/qemu-server/134.conf:net0: virtio=A1:B2:C3:B4:D5:E6,bridge=vmbr0,firewall=1 | |
use strict; | |
use warnings; | |
open F, "grep -R hwaddr= /etc/pve |" or die "Cannot grep /etc/pve: $!\n"; | |
my %mac2sys; | |
foreach(<F>) { | |
next unless /\/(\d+)\.conf:([^:]+): .+,hwaddr=([^,]+),/ | |
or /\/(\d+)\.conf:([^:]+): .*virtio=([^,]+),/; | |
my ($vm, $iface, $macaddr) = ($1,$2,$3); | |
my $a = ( $mac2sys{$macaddr} ||= {} ); | |
($a->{"$vm:$iface"} ||= 0)++; | |
} | |
foreach my $m (keys %mac2sys) { | |
next if scalar keys %{$mac2sys{$m}} == 1; | |
print "$m\n"; | |
print "\t$_\n" foreach keys %{$mac2sys{$m}}; | |
} | |
## END ## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment