Perl Connect Script
From LB Wiki
When I’m diagnosing load balancing issues, there are three really critical tools I use:
- TCPDump
- HTTP Header dump (such as Live HTTP Headers)
- Telnet
Yup, telnet. I don’t know about anyone else, but I use telnet excessively. Basically, I use it to test TCP connectivity, and with a quick “GET /”, to test to see if the web server is responding.
Most modern telnet implementations, including the one on F5’s BIG-IP version 9, include the ability to choose your source IP address (-b [IP address]). BIG-IP version 4, however, doesn’t seem to have this ability.
This was frustrating when trying to test some firewall and routing issues with the BIG-IP’s SNAT address. One issue that can come up is when you setup health checking, everything works out, because the IPs are generally that of the BIG-IP’s self IPs. But because the SNAT is a different IP, routing or firewall issues may crop up and block the connection. So I wrote a little Perl script that allows me to test connections with various source IP addresses. It makes a simple TCP connection and reports whether it’s successful or not, while allowing me to specify the source IP address. It’s very utilitarian, without any Jobsian niceties, so I may punch it up some more.
#!/usr/bin/perl
use IO::Socket;
$num = $#ARGV + 1;
if ($num != 3)
{
die "Usage: ptelnet [source IP] [destination IP] [destination port]“;
}
$localIP = $ARGV[0];
$destIP = $ARGV[1];
$destport = $ARGV[2];
$remote = IO::Socket::INET->new(
Proto => “tcp”,
LocalAddr => “$localIP”,
PeerAddr => “$destIP”,
PeerPort => “$destport”,
Reuse => 1
)
or die “Can’t connect to port $destport at $destIP from $localIP”;
print “Connection successful to “, $remote->peerhost, ” on port:
“, $remote->peerport, ” from “, $remote->sockhost, “n”;
close($remote);
