use Net::OpenSSH; my $hostname ='50.10.0.11'; my $username ='root'; my $password ="mypassword"; my $timeout = 15; my $mac = "00:25:B5:11:11:12"; my $ssh = Net::OpenSSH->new($hostname, timeout => $timeout, user => $username, password => $password); $ssh->error and die "unable to connect to remote host: " . $ssh->error; my ($dhcpip) = $ssh->capture("grep -i $mac /var/log/messages | grep DHCPACK | awk {'print \$8'} |uniq"); $ssh->error and die "remote command failed: " . $ssh->error; chomp $dhcpip; my @tr_output = $ssh->capture("traceroute $dhcpip | awk '{print \$2}'"); $ssh->error and die "remote command failed: " . $ssh->error; print "TRACEROUTE OUTPUT = @tr_output\n"; if(grep(/$dhcpip/,@tr_output)) { print "Trace route Success.. DHCP-IP = $dhcpip\n"; } else { print "Trace route : FAIL\n"; }