PDA

View Full Version : determining ports that are in use


albockiole
01-23-2002, 01:33 AM
There was a similar post earlier about blocking a port over a LAN, but how can you find out which ports are in use, so you can block the offending port?

I seem to remember reading somewhere that there was a program you could run in the terminal that would report what ports were in use (and could also refresh at a user-defined interval), but I can't remember what that program is.

Anyone out there know how I can determine what ports are in use on my computer?

thanks in advance...

blb
01-23-2002, 02:35 AM
netstat -nf inet will show all current connections, TCP and UDP. netstat -anf inet will add listening ports to this; basically, the LISTEN port is where a server (or daemon) is sitting, waiting for a connection.

If you want to know which process is listening to a port, use lsof. For example:


$ netstat -anf inet
...
tcp 0 0 127.0.0.1.1033 *.* LISTEN


so I want to know who's listening on port 1033, I'd use lsof:


$ sudo lsof -i :1033
...
netinfod 207 root 6u inet 0x01a9cd1c 0t0 TCP localhost:1033 (LISTEN)


(the interesting one being the LISTEN state again, the others are currently connected). In this case, 1033 is the NetInfo daemon (netinfod).

Gwyrrdin
01-23-2002, 06:13 AM
this command works great....

Read the manpage for more options...

% lsof -i -n -P

Gives a very complete overview of all your networkconnections.

Good Luck

Gwyrrdin

albockiole
01-25-2002, 01:35 PM
Thanks for the tips everyone...

It turns out the program I wanted to block is using a random port everytime it starts up, so it's making it very difficult to do so.

Oh well, at least I know how to take care of the static ones.

Thanks...