-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathget_macs.pl
executable file
·61 lines (39 loc) · 949 Bytes
/
get_macs.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl
=head1 NAME
get_macs.pl
=head1 SYNOPSIS
./get_macs.pl --username admin --password foo --host virtualcenter
=head1 ARGUMENTS
=over
=item --help
Show the arguments for this program.
=back
=head1 DESCRIPTION
Find the MAC addresses of all the NICs for all the VMs on B<virtualcenter>.
=head1 SEE ALSO
L<VMware Perl SDK|http://www.vmware.com/support/developer>
=head1 AUTHOR
Jonathan Barber - <[email protected]>
=cut
use strict;
use warnings;
use VMware::VIRuntime;
$Util::script_version = "1.0";
Opts::parse();
Opts::validate();
Util::connect();
# Get all VMs
my $vms = Vim::find_entity_views(
view_type => 'VirtualMachine',
);
my @guests;
# Iterate over the VMs, getting their IPs and OS
foreach my $vm (@{ $vms }) {
my @nics = grep {
$_->isa("VirtualEthernetCard")
} @{ $vm->config->hardware->device };
for my $nic (@nics) {
print $nic->macAddress, " ", $vm->name, "\n";
}
}
Util::disconnect();