How to Determine Which Programs are Using Which Ports

(0 votes, average 0 out of 5)

Sometimes a program is using a particular port, preventing another program from capturing and using it. It can be difficult to trace down which process exactly is using the port. Fortunately, there are a couple helpful utilities which can link each process with the port(s) it is using.

Windows

On Windows, download and run CurrPorts. It will display a table of the currently running processes and the ports they are using. It is possible to sort by process name or the port number to make it easy to find the desired port. CurrPorts is freeware by NirSoft.

currports

 

Linux

On Linux, this functionality is built-in with the lsof or netstat commands. Both of these commands display the open ports, but each gives somewhat different information:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ lsof -i tcp
rhythmbox  9643 user   38u  IPv4  7807452      0t0  TCP myhostname.local:32922->xxx.xxx.xxx.xxx:www (CLOSE_WAIT)
dropbox    9657 user   19u  IPv4  7812811      0t0  TCP myhostname.local:52059->www.dropbox.com:https (CLOSE_WAIT)
dropbox    9657 user   23u  IPv4  7812913      0t0  TCP *:17500 (LISTEN)
dropbox    9657 user   24u  IPv4 44107433      0t0  TCP myhostname.local:39794->xxx.xxx.xxx.xxx-static.reverse.softlayer.com:https (CLOSE_WAIT)
telepathy 13299 user    9u  IPv4 44161959      0t0  TCP myhostname.local:60768->xxx.xxx.xxx.xxx:https (ESTABLISHED)
chrome    16881 user  168u  IPv4 44071467      0t0  TCP myhostname.local:40527->xxx.xxx.xxx.xxx:https (ESTABLISHED)
 
$ lsof -i udp 
COMMAND  PID   USER   FD   TYPE  DEVICE SIZE/OFF NODE NAME
skype   9627 user   19u  IPv4 7804873      0t0  UDP localhost:42966 
skype   9627 user   39u  IPv4 7804926      0t0  UDP *:2805 
dropbox 9657 user   18u  IPv4 7812909      0t0  UDP *:17500 
 
$ netstat -pl
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:2805                  *:*                     LISTEN      9627/skype      
tcp        0      0 *:ssh                   *:*                     LISTEN      -               
tcp        0      0 localhost:ipp           *:*                     LISTEN      -               
tcp        0      0 *:17500                 *:*                     LISTEN      9657/dropbox             
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN      -               
udp        0      0 *:mdns                  *:*                                 -               
udp        0      0 localhost:42966         *:*                                 9627/skype      
udp        0      0 *:bootpc                *:*                                 -               
udp        0      0 *:bootpc                *:*                                 -               
udp        0      0 *:2805                  *:*                                 9627/skype      
udp        0      0 *:51959                 *:*                                 -               
udp        0      0 *:17500                 *:*                                 9657/dropbox    

Mac OS X

The syntax on Mac OS X is similar to Linux, except it may be necessary to specify the protocol with netstat:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ netstat -pl tcp
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 *:2805                  *:*                     LISTEN      9627/skype      
tcp        0      0 *:ssh                   *:*                     LISTEN      -               
tcp        0      0 localhost:ipp           *:*                     LISTEN      -               
tcp        0      0 *:17500                 *:*                     LISTEN      9657/dropbox               
tcp6       0      0 localhost:ipp           [::]:*                  LISTEN      -               
udp        0      0 *:mdns                  *:*                                 -               
udp        0      0 localhost:42966         *:*                                 9627/skype      
udp        0      0 *:bootpc                *:*                                 -               
udp        0      0 *:bootpc                *:*                                 -               
udp        0      0 *:2805                  *:*                                 9627/skype      
udp        0      0 *:51959                 *:*                                 -               
udp        0      0 *:17500                 *:*                                 9657/dropbox  
Partner Links:
 
Related Articles

» Mirror Website Directory Over FTP

You can easily mirror the contents of a directory over FTP using the lftp program on Linux. To connect, create a configuration file for lftp that specifies the credentials for the ftp server, the directory on the remote ftp server that you want to download files from, and where you want to place them on the local machine:123456set ftp:anon-user "ftpusername"set ftp:anon-pass "ftppassword"set ftp:ssl-allow noopen remote-ftp-server.commirror -c /remote/directory/...

» Execute a command remotely over SSH and then close the connection

It is possible to execute a command on a remote system using the ssh command. It is best if you if you want to run this from a script. An example would be retrieving the amount of memory usage:1ssh user@myremotemachine free -mThis works well except that even after the free -m command is run, the SSH connection is not terminated. Thus, if this is used in a script it may cause the script to quit prematurely or introduce some other undesireable behavior. To ensure that the SSH connection is...

» Understanding File and Folder Permissions (POSIX) on Linux and Mac OS X (using chmod)

Linux and Mac OS X both use a -compatible type of filesystem. This has to do with the way files are accessed by their owner and others. Files and folders have permissions for 3 different types of users:Owner: this is the user who owns the file or folderGroup: this is the permissions for any user in the group that the file belongs toOthers: this is the permissions for all other users who don't fall into one of the two above categoriesFor each of these types of users, there are 3 different...