Hello
I guess it all depends on if this will be automated and what you want to do with the result.
The fastest way to check if a port is open is to telnet to the host on that port.
Nmap might be useful for you,
www.insecure.org/nmap. It will provide the ability to scan multiple ports to see if they are open and then give you a nice reponse you can either look at or add into your script.
casphar@host:~# nmap -p 80 localhost
Starting nmap 3.93 (
http://www.insecure.org/nmap/ ) at 2005-12-04 11:38 PST
Interesting ports on localhost (127.0.0.1):
PORT STATE SERVICE
80/tcp open http
Nmap finished: 1 IP address (1 host up) scanned in 0.018 seconds
casphar@host:~#