Saturday, October 23, 2010

How to check or identify which process is listening to port 80 in windows

From yesterday, on my computer I could not start my apache service. From the XAMPP Control Panel Application whenever I start Apache it fails to start. I reinstalled apache several time but it could not help . In fact after installing Apache HTTPD web server or Microsoft IIS Internet Information Services web server, or any other application software or service and daemon that requires to open and listen to port 80 (HTTP) or port 443 (HTTPS SSL) it fails. So I consider myself to investigate about the program that is using port 80 or 443.

I am sure that a program is using port 80 or port 443 and restrict apache to use these port as I get following after installing Apache web server using XAMPP.

(OS 10052) Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down


So, I need to identify the program which is listening to port 80 and kill that process or at least restrict that process to listen to port 80.

To following steps will help you to find the culprit one.

1)Open command prompt. You can do it by clicking your start menu, then select Run, type cmd in the Run box and hit enter.

2)I expect you will see command prompt here unless you have viruses in your computer that restrict to show. In the command prompt type,

>netstat -o -n -a | findstr 0.0:80
in order to determine the process ID which is using port 80.

or type,
>netstat -o -n -a | findstr 0.0:443
in order to determine the process ID which is listening to port 443.

or type,
>netstat -aon
in order to list all connection that is listening, established, starting, closing and all other states. As netstat -aon will list all connections so from that you need to manually search for line 0.0.0.0:80 or 0.0.0.0:443 to determine the process ID.

3)Determine the process ID which is listening to port 80 or 443.
A typical output from the above commands are,
E:\Documents and Settings\Arju>netstat -o -n -a | findstr 0.0:80
TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4712

E:\Documents and Settings\Arju>netstat -o -n -a | findstr 0.0:443
TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       4712
UDP    0.0.0.0:443            *:*                                    316

E:\Documents and Settings\Arju>netstat -aon

Active Connections

Proto  Local Address          Foreign Address        State           PID
TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4712
TCP    0.0.0.0:135            0.0.0.0:0              LISTENING       1324
TCP    0.0.0.0:443            0.0.0.0:0              LISTENING       4712
TCP    0.0.0.0:3306           0.0.0.0:0              LISTENING       1920
TCP    0.0.0.0:5101           0.0.0.0:0              LISTENING       7636
TCP    0.0.0.0:17536          0.0.0.0:0              LISTENING       316
TCP    10.65.49.113:1175      118.160.238.122:80     ESTABLISHED     316
TCP    10.65.49.113:1451      209.85.137.125:5222    ESTABLISHED     1588
TCP    10.65.49.113:1561      66.102.9.83:80         CLOSE_WAIT      3436
TCP    10.65.49.113:1623      96.17.159.66:80        CLOSE_WAIT      1964
TCP    10.65.49.113:2659      216.10.192.112:80      CLOSE_WAIT      5164
TCP    10.65.49.113:2782      216.10.192.112:80      CLOSE_WAIT      3692
TCP    10.65.49.113:3084      74.125.87.83:80        ESTABLISHED     2736
TCP    10.65.49.113:3179      74.125.87.191:80       ESTABLISHED     2736
TCP    10.65.49.113:3180      74.125.87.83:80        ESTABLISHED     2736
TCP    10.65.49.113:3185      74.125.87.101:443      ESTABLISHED     5164
TCP    10.65.49.113:3187      74.125.87.147:80       ESTABLISHED     5164
TCP    10.65.49.113:3850      68.180.217.28:5050     ESTABLISHED     7636
TCP    10.65.49.113:3881      68.142.233.181:80      ESTABLISHED     7636
TCP    10.65.49.113:4837      207.46.125.86:1863     ESTABLISHED     320
TCP    127.0.0.1:1247         0.0.0.0:0              LISTENING       3692
TCP    127.0.0.1:1557         0.0.0.0:0              LISTENING       6172
TCP    127.0.0.1:1557         127.0.0.1:1558         ESTABLISHED     6172
TCP    127.0.0.1:1558         127.0.0.1:1557         ESTABLISHED     7928
TCP    127.0.0.1:1672         0.0.0.0:0              LISTENING       1532
TCP    127.0.0.1:1727         127.0.0.1:1728         ESTABLISHED     7636
TCP    127.0.0.1:1728         127.0.0.1:1727         ESTABLISHED     7636
TCP    127.0.0.1:1990         127.0.0.1:1991         ESTABLISHED     5164
TCP    127.0.0.1:1991         127.0.0.1:1990         ESTABLISHED     5164
TCP    127.0.0.1:1993         127.0.0.1:1994         ESTABLISHED     5164
TCP    127.0.0.1:1994         127.0.0.1:1993         ESTABLISHED     5164
UDP    0.0.0.0:443            *:*                                    316
UDP    0.0.0.0:17536          *:*                                    316
UDP    10.65.49.113:123       *:*                                    1364
UDP    10.65.49.113:1900      *:*                                    1500
UDP    127.0.0.1:123          *:*                                    1364
UDP    127.0.0.1:1025         *:*                                    1924
UDP    127.0.0.1:1171         *:*                                    316
UDP    127.0.0.1:1716         *:*                                    320
UDP    127.0.0.1:1730         *:*                                    7636
UDP    127.0.0.1:1900         *:*                                    1500
UDP    127.0.0.1:2993         *:*                                    1588
UDP    127.0.0.1:9877         *:*                                    1924
UDP    127.0.0.1:9977         *:*                                    1924
UDP    127.0.0.1:62976        *:*                                    1924

From the above output we see process ID 4712 is the culprit one which is listening to port 80 and 443 and thus restrict web server to use them.

4)In this step find the process which has the Process ID 4712. You can simply follow  http://dbatutorials.blogspot.com/2010/10/how-to-know-process-id-or-pid-on.html and bring task manager to display that process ID. From task manager Image Name determine the process name.

So now you can kill that process or still if you want to run that process first run you web server/apache and then run that program. In this way apache first will listen to port 80 and that program will not be able to use as it starts after web server.

No comments:

Post a Comment