1829596 Members
1849 Online
109992 Solutions
New Discussion

checking port number

 
Chern Jian Leaw
Regular Advisor

checking port number

HI,

How do I check if a particular port number is already being used by another process in a client-server communication?

I did:
# netstat |grep 7412
which displays all machines communicating with the local machines on the respective port numbers. I'd have to then check each port numbers used for within the local machine to see if the number which I'm looking for is that list or not.

Are there any other more efficient way of doing this? Or could anyone show me how I could write a script do check if a particular port number is already been used, then generate another number?

Thanks.
3 REPLIES 3
Bill McNAMARA_1
Honored Contributor

Re: checking port number

You could try lsof..
http://hpux.cs.utah.edu/

Later,
Bill
It works for me (tm)
Michael Tully
Honored Contributor

Re: checking port number

You need to download and install 'lsof' from the HP porting centre.

http://hpux.cs.utah.edu/hppd/hpux/Sysadmin/lsof-4.61/

If your after the 64 bit version, this link will help.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x1de9f715edc6d5118ff10090279cd0f9,00.html

Anyone for a Mutiny ?
Michael Tully
Honored Contributor

Re: checking port number

Once you've downloaded and install 'lsof' here is a frew examples of it's usage.

To which files are open for a given process id (pid)

# lsof -p

To see all the open files associated with a particular command.

# lsof -c midaemon

User name.

# lsof -u
# lsof -u

processes being used via a socket.

# lsof -i tcp:23
# lsof -i udp:123

Anyone for a Mutiny ?