#!/usr/bin/perl #nagios return codes: 0->All Good, 2->Critical use Net::Nslookup; use Socket; #global var. exit status# $exit_status = 0; sub GetIps { #here we are getting the ip addresses and populating the ip array @ips; @ips= nslookup(domain =>"google.com"); } sub FirstCheck { foreach (@ips) { $socket = new IO::Socket::INET->new(PeerAddr => $_, PeerPort => '777', Proto => 'tcp', Timeout => 2, ) or print "could not create bind to $_. port 777: $@\n" and $exit_status=2 ; close($socket); } } sub SecondCheck { foreach (@ips) { $socket = new IO::Socket::INET->new(PeerAddr => $_, PeerPort => '443', Proto => 'tcp', Timeout => 2, ) or print "could not create bind to $_. port 443: $@\n" and $exit_status=2; close($socket); } } #calling in the subz! &GetIps; &FirstCheck; &SecondCheck; #exiting the program with an exit status. exit ($exit_status);