Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I find out which ports are open?  RSS feed

 
Dennis Hicks
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!