Finding Open Ports

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Finding Open Ports

 
0
  #1
May 6th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Finding Open Ports

 
0
  #2
May 6th, 2005
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: Finding Open Ports

 
0
  #3
May 6th, 2005
thanx, thats what i thought. do you know how to check if they're occupied or not?

Thank you
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 348
Reputation: paradox814 is an unknown quantity at this point 
Solved Threads: 4
paradox814's Avatar
paradox814 paradox814 is offline Offline
Posting Whiz

Re: Finding Open Ports

 
0
  #4
May 6th, 2005
uhm, maybe a BindException or a PortUnreachableException but i'm not sure
Reply With Quote Quick reply to this message  
Join Date: Aug 2004
Posts: 350
Reputation: Ghost is an unknown quantity at this point 
Solved Threads: 2
Ghost's Avatar
Ghost Ghost is offline Offline
Posting Whiz

Re: Finding Open Ports

 
0
  #5
May 6th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Finding Open Ports

 
0
  #6
May 7th, 2005
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC