views:

5981

answers:

8

Hi there,

I need to find out what ports are attached to which processes on a unix machine (HP Itanium). Unfortunately, the lsof is not installed and I have no way of installing it.

Does anyone know an alternative method? A fairly lengthy google hasn't turned up anything.

Thanks.

+6  A: 

netstat -l (assuming it comes with that version of UNIX)

David Dorward
+2  A: 

Try "pfiles PID" to show all open files for a process.

dogbane
A: 

I know FreeBSD has sockstat.

Tim Sally
lsof is unavailable.
ΤΖΩΤΖΙΟΥ
Ack, it's late :-p
Tim Sally
+4  A: 

Given (almost) everything on unix is a file, and lsof lists open files...

Linux : netstat -putan or lsof | grep TCP

OSX : lsof | grep TCP

Other Unixen : lsof way...

lms
Please read the question: lsof is unavailable.
ΤΖΩΤΖΙΟΥ
+3  A: 
netstat -pln

EDIT: linux only, on other UNIXes netstat may not support all these options.

Sergei Stolyarov
+1  A: 
netstat -ln | awk '/^(tcp|udp)/ { split($4, a, /:/); print $1, a[2]}' | sort -u

gives you the active tcp/udp ports. Then you can use the ports with fuser -n tcp or fuser -n udp, as root, and supposing that fuser is GNU fuser or has similar options.

If you need more help, let me know.

ΤΖΩΤΖΙΟΥ
+1  A: 

Assuming this is HP-UX? What about the Ptools - do you have those installed? If so you can use "pfiles" to find the ports in use by the application:

pfiles prints information about all open file descriptors of a process. If file descriptor corresponds to a file, then pfiles prints the fstat(2) and fcntl(2) information.

If the file descriptor corresponds to a socket, then pfiles prints socket related info, such as the socket type, socket family, and protocol family.

*In the case of AF_INET and AF_INET6 family of sockets, information about the peer host is also printed.*

For example, see http://www.theunixblog.com/2007/01/find-out-which-process-is-using-port.html

Jay
A: 

Thanks all for your input. My main problem here is that I don't have permissions on the box to install anything. I've managed to solve my specific problem anyway.

gnuchu
You should answer your question then so that others who end up reading this with same or similar problem may be able to use th einfo.
mattlant
Yeah, I normally would have done that but in this case my solution won't answer the question I asked.
gnuchu
Probably if you have found a work around that would help others looking for answers....
Neer