Page Index Toggle Pages: 1 Send TopicPrint
Locked Topic Pinging a port, returning a value. (Read 953 times)
-G-
New Member
*
Offline


Yes Dear. I'm working
on it ...

Posts: 7
Joined: Mar 2nd, 2003
Pinging a port, returning a value.
Mar 7th, 2003 at 8:29pm
 
Here is the script that has served well for me for years (nope, not mine), except now with the web site on a unix shell server, it never displays the status GIF. As near as I can tell it's because the ping is never sent to the remote system. The remote system is mine, it will return a reply and the program on that port will also respond to it .. it always has.

IP needed to ping: 66.216.60.251
PORT needed directed to:  2593
It needs to diplay one of two pics based on a ping reply or not.

I know squat about programming/scripting other then what my game uses and I would do it myself except time contraints prevent the necessary learning period. Soooo, I am looking for a kind soul who can do up one for me.

Here is the original script and readme:
Code
Select All
use Socket;
use CGI;
#!/usr/bin/perl

###############################################################################
# PortPing     copyright 1998 Eric D. Patterson.	(Anarchy inK, 02/1999)
# This program attempts to connect to a socket on a remote server, and returns
# an image indicating wheither that port is currently up or down.  Pretty
# simple, but handy, and useful for modification into other scripts.
#
# This script is free for use and mdification so long as this header remains
# unmodified and intact.  Anarchy inK, and Eric Patterson will not
# be held liable for distress, loss, or damages that may result from the use of
# this program.
#
# Anarchy inK refers to Anarchy inK Co.
# http://www.anarchyink.com
###############################################################################
# Variables you can edit:
$up = "Location: http://www.michaelmarino.net/tfl/up.gif\n\n";
$down = "Location: http://www.michaelmarino.net/tfl/down.gif\n\n";
###############################################################################

sub checkPort {  #checks the status of an input address and port, returns T/F
  my ($remote, $port, $iaddr, $paddr, $proto, $line, $ret);
  $remote = shift || @_[0];
  $port = shift || @_[1];
  @_ = "";
  if ($port =~ /\D/){ $port = getservbyname($port, 'tcp') }
  die "No such port" unless $port;
  $iaddr = inet_aton($remote) or die "Unable to contact remote host: $remote";
  $paddr = sockaddr_in($port, $iaddr);
  $proto = getprotobyname('tcp');
  socket(SOCK, PF_INET, SOCK_STREAM, $proto) or die "Socket connection error: $!";
  $ret = (connect(SOCK, $paddr));
  close (SOCK) or die "Socket close error: $!";
  return $ret;
}

###############################################################################
#Main stuff
###############################################################################
  $query = new CGI;
  $host = $query->param('host'); #accept "host" as hostname input parameter
  $port = $query->param('port'); #accept "port" as portnum input parameter

  if (checkPort($host, $port)){
    print $up;
  }else{
    print $down;
  }
 



This is the included readme:
Code
Select All
Port Ping - a Shard Commander utility
-------------------------------------
     Copyright 1999 Anarchy inK


Installation:

1) Copy up.gif and down.gif into the web root on your web server.

2) Change the first line of portping.cgi using notepad or another text editor
	to the path of your perl interpreter.

3) Copy portping.cgi into the cgi-bin on your web server.


4) Add the following line of HTML to a page on your web server:

	<img src="/cgi-bin/portping.cgi?host=your_ip&port=2593" border=0>

	where your_ip = the ip address of your shard

5) Be sure to add our copyright to your page. It is part of the license agreement.

	<A HREF="http://www.anarchyink.com/sc">Shard Commander</A> is
	©1999 <A HREF="http://www.anarchyink.com" TARGET="_top">Anarchy
	inK</A> · All Rights Reserved.

6) Go to the page and test it. 



If anyone can do this, great and many thanks, if not .. well .. in some few months I might just figure out how  Tongue
  
Back to top
WWW  
IP Logged
 
fess
Guest


Re: Pinging a port, returning a value.
Reply #1 - Mar 8th, 2003 at 11:30pm
 
God help me for getting side tracked on this, but it only took 5 minutes to test it.

The script works fine on unix, once you fix the top three lines.

(and remember to pass it args in the url  without ?port=2593&host=66.216.60.251  it just "dies" with server error  )

anyhow  fix the first three lines,

instead of:
[code]
use Socket;
use CGI;
#!/usr/bin/perl
[/code]

it should be:

[code]
#!/usr/bin/perl
use Socket;
use CGI;
[/code]

the first #! line tells  unix this is an interperated script, the  /usr/bin/perl part of that line says to use the program /usr/bin/perl to interperat the script, so unix  fires off /usr/bin/perl telling it to run your script.

you should make sure that the file has got unix line endings after you upload it ie: "\n"
not dos  line endings ie: "\r\n"  or  it might try to interperate "/usr/bin/perl" as "/usr/bin/perl\r" which there won't be any program of that name.

if you have that probelm, the script won't even run from the command line.  upload in text mode, that translates the files correctly so  that problem goes away.

also sometimes perl is in another location, like "/usr/local/bin/perl"
so you might have to change it to that. 

also make sure the script is executable.

chmod +x portping.cgi

blah.
well, now  spent more than  five minutes
  
Back to top
 
IP Logged
 
Christer Alexander
God Member
*****
Offline


Make my day...

Posts: 3443
Location: Lethbridge
Joined: Feb 10th, 2002
Gender: Male
Re: Pinging a port, returning a value.
Reply #2 - Mar 9th, 2003 at 12:06am
 
[actually, DOS uses \n\r as linebreaks, not \r\n]
  

Code
Select All
unless(0) { stab("LoonyPandora"); next; } 

Back to top
IP Logged
 
-G-
New Member
*
Offline


Yes Dear. I'm working
on it ...

Posts: 7
Joined: Mar 2nd, 2003
Re: Pinging a port, returning a value.
Reply #3 - Mar 9th, 2003 at 12:15am
 
And the world is a much happier place .. at least, mine is.  Many thanks.

I looked at the top lines, but not knowing the full purpose of the first two, I did not realize they needed to be after the perl path.  The script is happily doing it's thing and now I can move on to bigger better things to mess up  Smiley

thx again.
  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint