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.

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

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

Thank you

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.