how to find port numbers a web server is listening to

I want to write a program to list all port numbers a process like web server is listening to.Is there a any unix command to find the port numbers and the processes(pid) connected to that port.

u can write the script in shell for a particular task of listing

in linux we have commands
lsof -i TCP (displays online open tcp ports)
lsof -i UDP
above commands work for linux only

netstat -anp | head -20

nmap -anp ( if the nmap utility is installed in linux system)

thru netstat only we can get much of the information regarding the open ports

you can also use "sockstat" if applicable.

sockstat works on BSD
netstat can be used for unix platform of solaris,hpux

netstat -na |grep LISTEN to find the listening ports in HP-UX,Solaris

netstat -na|grep CONNECTED to find the ports connected in Linux box.

On solaris:

pfiles <pid>

You can try, on linux,

 # netstat -lpn | grep httpd  

.. if you know that the server is httpd (apache), there you can figure out what ports and address has apache bound to as well as process' pid.

on freebsd systems try

# sockstat -ln | grep httpd