• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 821
  • 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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

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