Operating System - HP-UX
1819732 Members
3098 Online
109606 Solutions
New Discussion юеВ

Re: Need for a simple TCP port query tool

 
Fedon Kadifeli
Super Advisor

Need for a simple TCP port query tool

I am trying to implement a simple availability reporting tool. I am planning to write scripts that will periodically access some TCP ports on some servers (like ORASRV:1521, APPSRV:22 etc.) and report the daily, monthly and yearly availibilities of the services provided on these TCP ports.

To do this, I need a very simple "Port Query" command-line tool that will return an exit code (0 or non-zero) depending on the status of the port (Listening, rejected, time-out etc). The tool should only connect to the given TCP port and then close the connection immediately (no data should be sent or received).

I have looked at the "strobe" (A super optimised TCP port surveyor) utility at http://hpux.connect.org.uk/hppd/hpux/Networking/Admin/strobe-1.06/ but it didn't meet my requirements.

What I need is an HP-UX equivalent of the Windows "portqry" command ( http://support.microsoft.com/default.aspx?scid=kb;en-us;310099 ).
12 REPLIES 12
Robert-Jan Goossens
Honored Contributor

Re: Need for a simple TCP port query tool

Hi Fedon,

You could take a look at lsof.

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/lsof-4.76/

running lsof on a specific tcp/udp port will return if a port is in use and which processes are using the port.

# lsof -i tcp:1712
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
inetd 982 root 28u inet 0x41df2068 0t0 TCP *:registrar (LISTEN)
psmctd 1933 root 1u inet 0x416b3a68 0t45799 TCP dbxxx:56824->dbxxx:reg)
registrar 1973 root 0u inet 0x420aee68 0t45799 TCP dbxxx:registrar->dbxxx)
registrar 1973 root 1u inet 0x420aee68 0t45799 TCP dbxxx:registrar->dbxxx

Hope this helps,
Robert-Jan
Fedon Kadifeli
Super Advisor

Re: Need for a simple TCP port query tool

Hi Robert,

Since this will be an availability reporting tool, I am planning to run the scripts on separate (preferably multiple) hosts (ie, not on the hosts running the applications). I need a tool that will query the port status accross the network.
Antonio Cardoso_1
Trusted Contributor

Re: Need for a simple TCP port query tool

Hi Fedon,
netstat command would also meet your requirements, for example:

listening service:
# netstat -na | grep 3306
tcp 0 0 *.3306 *.* LISTEN
# echo $?
0

non-listening service:
# netstat -na | grep 1521
# echo $?
1
Antonio Cardoso_1
Trusted Contributor

Re: Need for a simple TCP port query tool

To run this across the network, consider using ssh software available at HP's software depot for free:
http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=T1471AA
Fedon Kadifeli
Super Advisor

Re: Need for a simple TCP port query tool

Hi Antonio,

The same response applies. I need to test the availability of these ports from separate hosts, i.e. across the network.
Fedon Kadifeli
Super Advisor

Re: Need for a simple TCP port query tool

Hi again Antonio,

The service ORASRV:1521 may be running perfectly, but ORASRV:22 (secure shell) may not be running!
Antonio Cardoso_1
Trusted Contributor

Re: Need for a simple TCP port query tool

Fedon,
an alternative to remotely check services availability may be to use the attached script.

From your central test point, you run the script:
tstsvc.pl

For example:
tstsvc.pl ORASRV 1521
tstsvc.pl APPSRV 22

and check return code.

This should do the job,
regards,
antonio.
Fedon Kadifeli
Super Advisor

Re: Need for a simple TCP port query tool

Antonio,

Thank you very much for the effort. Writing a Perl script was my last resort also. I was wondering if there is a binary to do the same job.
Fedon Kadifeli
Super Advisor

Re: Need for a simple TCP port query tool

Failing to find a binary for HP-UX, I wrote (actually adapted from various sources) the C code attached.

Thank you all...
H.Merijn Brand (procura
Honored Contributor

Re: Need for a simple TCP port query tool

For all interested: Vic released 4.77 today.

ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof

His mail about that reached my inbox at 15:05:05 MET (09:05:08 -0400)
He mails me, because I (usually) check all releases on all available OS's, which in my case includes HP-UX 10.20 through 11.23

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Bill Thorsteinson
Honored Contributor

Re: Need for a simple TCP port query tool

I would look at nagios for this kind of
monitoring. Configure a central server,
and install the remote agents on the other
servers. There are a variety of available
modules to test various protocols.
rick jones
Honored Contributor

Re: Need for a simple TCP port query tool

Well, telnet takes a port number as an optional second argument. You would want to make sure that the telnet client didn't attempt any "telnet-specific" negotiation or it might annoy the application at the other end - I cannot remember if specifying a port other than the standard telnet server port will do that automagically or not.

Apart from that, if you look in stuff like Stevens' Unix Network Programming, you should be able to find examples of small programs that connect to a given hostname/ip and port. The code would not be all that long at all.

Depending on the scripting language you are using, that language may already have some support for sockets.
there is no rest for the wicked yet the virtuous have no pillows