954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Finding Open Ports

Hi,

I was wondering if there was a way to find open ports on a server. I'm trying to write a program that tells the user whether they have any open ports or not and if they do, which ones and how to fix them.

Thanks.

Ghost
Posting Whiz
352 posts since Aug 2004
Reputation Points: 12
Solved Threads: 2
 

there are thousands of ports, i think it ranges from 1-65,536 the first 1,024 are reserverd ports even though not all of them have been claimed yet, so program should generally try and refrain from usign them, i think you would have to go through every single port and check to see if it is occupied to do this

also check out:
http://www.iana.org/assignments/port-numbers

paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

thanx, thats what i thought. do you know how to check if they're occupied or not?

Thank you

Ghost
Posting Whiz
352 posts since Aug 2004
Reputation Points: 12
Solved Threads: 2
 

uhm, maybe a BindException or a PortUnreachableException but i'm not sure

paradox814
Posting Whiz
351 posts since Oct 2004
Reputation Points: 13
Solved Threads: 4
 

do you think you might be able to give me some code (just 2 point me in the right direction, not give me the "answer") or the method to find the open ports?

Thank you.

Ghost
Posting Whiz
352 posts since Aug 2004
Reputation Points: 12
Solved Threads: 2
 

Try to open a ServerSocket on the port. If you can, the port was available and you immediately close the socket again.
If you cannot, you get an exception (or an errorcode, check the API docs for ServerSocket) and you know the port is in use already.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You