• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 815
  • Last Modified:

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

0
robstarox
Asked:
robstarox
  • 3
1 Solution
 
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
 
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now