how would I simulate an unavailable LDAP server in Net::LDAP

Im trying to return a value if the netldap server is unavailable and print out the error and such.  The first thing i try is to bind to the ldap server anonymously, and if it fails to print out data via a webpage...  I have the ldap server firewalled off and should not be able to connect.

As u can see if it doesnt result in  LDAP_SUCCESS,  it should technically print out the page ... But i think its giving an error before that because of the fact its not even making a connection to the ldap server...so would I put a die statement in there instead?  Im assuming its not resulting in a code whatsover, which is why its not printing that out.
# First, bind anonymously to test connectivity
$ldaps = Net::LDAPS->new ( 'servername', timeout => 10 );
$result = $ldaps->bind();
   if ($result->code() != LDAP_SUCCESS)
   {
                $pagehead = $pagetitle ='server unavailable';
                &PrintHead;
                print "<p style=\"margin:10pt;\">LDAP Server Unavailable\n.";
 
                exit 0;
   }

Open in new window

robstaroxAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TolomirAdministratorCommented:
No perl expert but how about something like this in front of the ldap connection:



$p = Net::Ping->new("icmp");
$p->bind($my_addr); # Specify source interface of pings
foreach $host (@host_array)
{
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
}
$p->close();

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robstaroxAuthor Commented:
I was looking more of a port checking than a simple ping...  How can I do a port check?
0
robstaroxAuthor Commented:
Figured it out myself.


#!/usr/bin/perl

use IO::SOCKET;

$handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => 'servername', PeerPort => '8080', timeout => "2" ) ;
if (!$handle)
        {  print "cant connect to ldap\n"; }

else  
{       print "connected\n";
}



#!/usr/bin/perl
 
use IO::SOCKET;
 
$handle = IO::Socket::INET->new(Proto => "tcp", PeerAddr => 'servername', PeerPort => '8080', timeout => "2" ) ;
if (!$handle)
        {  print "cant connect to ldap\n"; }
 
else  
{       print "connected\n";
}

Open in new window

0
robstaroxAuthor Commented:
Simple query to test port on another machine thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.