Operating System - HP-UX
1834413 Members
3886 Online
110067 Solutions
New Discussion

Re: Need UNIX system call to check the remote m/c is up or not

 
Vasudevan MV
Frequent Advisor

Need UNIX system call to check the remote m/c is up or not

Hi,

I have written a c++ program on HPUX-10.20, at one point I need to check whether the remote machine (HPUX-10.20) is active or not. But I want to use UNIX system call command rather than doing PING in a shell. Can any one tell me what command is that?

Thanks in advance
Vasu
4 REPLIES 4
Steven Sim Kok Leong
Honored Contributor

Re: Need UNIX system call to check the remote m/c is up or not

Hi,

If it is for C, you can download a copy of hping2 and look at the source.

hping2 is a tool which allows sending of crafted ICMP/TCP/UDP packets:

Hope this helps. Regards.

Steven Sim Kok Leong
Ron Kinner
Honored Contributor

Re: Need UNIX system call to check the remote m/c is up or not

Just bumping this up to the top since it was posted on a Saturday.

However, I suspect that there is no UNIX command to tell you if a remote sytem is up unless the local system already has some sort of UNIX relationship with the remote system such a remote file system. Any test of a remote system's status will be some variation of ping in that we have to send a packet and check for a response. The local system otherwise has no idea and couldn't really care less if another system is up or not.

Ron
Ron Kinner
Honored Contributor

Re: Need UNIX system call to check the remote m/c is up or not

If you can get the remote systems to run rpc.rstatd then you can use rup to find out their status.

Ron
SHABU KHAN
Trusted Contributor

Re: Need UNIX system call to check the remote m/c is up or not

Hi,

Here is a perl script that you could use to check if the remote system is UP...
---------------------Cut here------------------
# Author : Shabu Khan/Alan Acevedo
#!/usr/local/bin/perl -w

# Initialize!
use IO::Socket;

$numarg = @ARGV;
if ($numarg != 2) {
print "usage: tcpping \n";
exit 1;
}
$host=$ARGV[0];
$tcpport=$ARGV[1];

# Main
$socket=IO::Socket::INET->new
(
PeerAddr => "$host",
PeerPort => "$tcpport",
Proto => "tcp",
Type => SOCK_STREAM
) or die "Could not open port $tcpport.\n";

print "Able to open port $tcpport.\n";
close($socket);

---------------------Cut here------------------
There was a need for us to write something like this in my previous project..

You could test something like this..

./tcpping hostname 23

If the system is alive it will say "Able to open port" else it will say "Could not open port"... you could capture these messages in a variable in your script or however you would like to handle it...

Enjoy !

-Shabu Khan