File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes How can I find out which ports are open? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "How can I find out which ports are open?" Watch "How can I find out which ports are open?" New topic
Author

How can I find out which ports are open?

Dennis Hicks
Greenhorn

Joined: Jul 09, 2001
Posts: 12
Hi all -
I apologise if this has been covered already, but I did a quick search and couldn't find an answer.
I'm trying to find a way of finding out what ports/sockets are open on a machine at any point in time - so I'm after some method to return a list of open ports.
Ideally I was hoping there'd be a method in java.net that returned an enumeration of open ServerSockets that I could traverse, but couldn't find anything.
Has anyone done this or have any ideas? There's plenty of examples showing how to open a ServerSocket and then connect to that known socket - but what if you don't know the port number?
Cheers-
Den
pal kandy
Greenhorn

Joined: Jan 17, 2002
Posts: 9
hi Den,
all the info regarding active ports on Windows platforms is given by netstat command. if u r looking to see this info thru some java program then u'll have to use Runtime class to execute this in command prompt.
Regards,
Nitin
Dennis Hicks
Greenhorn

Joined: Jul 09, 2001
Posts: 12
Thanks for the tip - I didn't think of running a host machine tool to find it out. :roll:
I was just hoping to do it all in the code and not have to call an external tool, but I guess I can invoke netstat. How I'll parse the output from it, I have no idea.
Thanks again,
Den
 
 
subject: How can I find out which ports are open?
 
Threads others viewed
Port scanning
How do I find out what services occupy which port?
Problem with JMS Ports in JBoss
Looking for open source gateway
Not able to connect to localhost:8080??
MyEclipse, The Clear Choice