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

» Grant Write Access to CIFS Mount As A Regular User

Often you may want a cifs/smbfs (Samba) mount on Linux to be writeable by normal users. If it is the case that you can write to the mounted filesystem as root but not as a normal user (Permission Denied), then you may need to adjust your mount options in /etc/fstab. The key mount options are file_mode and dir_mode, which override the default file and directory permissions for Samba shares. By manually setting these values, you can grant read/write access to normal users on the local...

» 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/...

» Mount a WebDAV filesystem (like box.net) on Linux using davfs2

You can easily mount a WebDAV filesystem on Linux so that you can access the files just like they were on your local computer. One way to do is to install the davfs2 package (this is the Ubuntu/Debian package name, though it should be similar for other distros). Once you have installed it, add an entry to /etc/davfs2/secrets with your login credentials for the WebDAV account. For box.net, the command would look like this:sudo echo “https://www.box.net/dav username password” >>...