use strict; use warnings; use Term::ReadKey; use VMware::VIRuntime; my $username = ""; my $password = ""; my $service_url = "https:///sdk/vimService"; my $ip = $ARGV[0]; unless (defined $ip) { die "No IP address specified.\n"; } sub PromptUserPassword { print "Enter password for $username: "; ReadMode('noecho'); $password = ReadLine(0); chomp $password; ReadMode(0); print "\n"; } # Prompt for user password if not defined in script: unless ($password) { PromptUserPassword(); } # Login to Virtual Center service: my $vim = Vim::login(service_url => $service_url, user_name => $username, password => $password); my $vms = Vim::find_entity_views( view_type => 'VirtualMachine', ); my $flag = 0; my ($v, $i, $n, $host); foreach $v ( @{$vms} ) { if ( defined $v->guest->net ) { foreach $n ( @{$v->guest->net} ) { if ( defined $n->ipAddress ) { foreach $i ( @{$n->ipAddress} ) { if ( $i =~ m/$ip/ ) { $host = Vim::get_view( mo_ref => $v->runtime->host ); print "IP $ip of guest ",$v->name," found on host ",$host->name,"\n"; $flag = 1; } } } } } } unless ($flag) { print "IP ($ip) not found.\n"; }