• RSS
  • Twitter
  • FaceBook

Security Forums

Log in

FAQ | Usergroups | Profile | Register | RSS | Posting Guidelines | Recent Posts

Script for testing status of a service

Users browsing this topic:0 Security Fans, 0 Stealth Security Fans
Registered Security Fans: None
Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More

View previous topic :: View next topic  
Author Message
Jason
Forum Fanatic
Forum Fanatic


Joined: 19 Sep 2002
Posts: 16777215


Offline

PostPosted: Fri Dec 20, 2002 7:39 pm    Post subject: Script for testing status of a service Reply with quote

I made this script for a friend, just thought i would post it incase anyone else needed something similar.

Basically, its a perl script that opens a connection to a pre-defined IP address and port. It can then return the status of that port, either up or down.

This is useful if you run a network, and want to check the status of certain daemons running on specific machines.


Quote:
#!/usr/bin/perl -w
#
# porttest.pl
#
# Perl Script to test connection to ports.
# Used for checking service / server availability


# we want to use sockets
use IO::Socket;

# test that 2 parameters have been passed to script. If not, quit
$ARGC=@ARGV;
if ($ARGC !=2) {
print "Usage: perl porttest.pl <hostIPaddress> <portnumber> \n";
exit;
}

# assign cmdline values to vars
$remo = $ARGV[0];
$openport = $ARGV[1];


# Test status, if unable to connect, quit with error msg DOWN
unless ($so = IO::Socket::INET->new (Proto => "TCP", PeerAddr => $remo,
PeerPort => $openport))
{
print "DOWN\n";
exit;
}

# Script got to this point, therefore not down, so write UP, and exit
print "UP\n";
close $so;
exit;


Here is the source of a php page that calls the script (by "Anigel", www.star-fury.com):

Quote:

<?
include ("../common.php");
include ("style2.php");
?>
<font size=+2>
<center>
<h3>Star-Fury Network Status</h3>
<P>
<pre>
<h3>Merlin</h3>
IRC <?system("/usr/local/sbin/porttest.pl merlin.star-fury.com 6667")?>
WWW <?system("/usr/local/sbin/porttest.pl merlin.star-fury.com 80")?>

<h3>Eclipse</h3>
IRC <?system("/usr/local/sbin/porttest.pl 127.0.0.1 6667")?>
WWW <?system("/usr/local/sbin/porttest.pl 127.0.0.1 80")?>

<h3>Trinity</h3>
WWW <?system("/usr/local/sbin/porttest.pl trinity.star-fury.com 80")?>

<h3>Oblivion</h3>
IRC <?system("/usr/local/sbin/porttest.pl oblivion.star-fury.com 6667")?>

</pre>
</font>
Thanks to <a href=http://www.jason-lambert.com>Jason Lambert</a> for theback end script<P>

<?
include("footer.php");


The direct link to a working example is here:
http://eclipse.star-fury.com/main/porttest.php

J


Last edited by Jason on Sat Dec 23, 2006 6:31 pm; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail
Anigel
Guest






PostPosted: Fri Dec 20, 2002 7:47 pm    Post subject: Reply with quote

Just for your information.

The up and down returns were modified to provide a direct link to the image in the above example

eg

# Test status, if unable to connect, quit with error msg DOWN
unless ($so = IO::Socket::INET->new (Proto => "TCP", PeerAddr => $remo,
PeerPort => $openport))
{
print "<img src=down.gif>\n";
exit;
}

# Script got to this point, therefore not down, so write UP, and exit
print "<img src=up.gif>\n";
close $so;
exit;
Back to top
flw
Forum Fanatic
Forum Fanatic


Joined: 27 May 2002
Posts: 16777215
Location: U.S.A.

Offline

PostPosted: Fri Dec 27, 2002 9:52 pm    Post subject: Reply with quote

Seems like alot of typing for ps -ax ? Or am I missing the point?
Back to top
View user's profile Send private message Visit poster's website
Jason
Forum Fanatic
Forum Fanatic


Joined: 19 Sep 2002
Posts: 16777215


Offline

PostPosted: Sat Dec 28, 2002 8:49 am    Post subject: Reply with quote

fastlanwan wrote:
Seems like alot of typing for ps -ax ? Or am I missing the point?


Correct.

The point is that this can test the status of a service on another machine. It is better than pinging, esp if ICMP is blocked by a firewall. Also, just becuase the machine is up, it does not mean a particular service on a particular port is working.. Smile
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   

Post new topic   Reply to topic   Printer-friendly version    Networking/Security Forums Index -> Programming and More All times are GMT + 2 Hours
Page 1 of 1


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Looking for more Windows Networking info?

Sign up to the WindowsNetworking.com Monthly Newsletter, written by Enterprise Security MVP Deb Shinder, containing news, the hottest tips, Networking links of the month and much more. Subscribe today and don't miss a thing!
View a sample newsletter.

Become a WindowsNetworking.com member!

Discuss your Windows Networking issues with thousands of other Windows Newtorking experts. Click here to join!

Community Area

Log in | Register

Readers' Choice

Which is your preferred data recovery solution?

Follow TechGenix on Twitter