• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding the Occupied ports in a Server

 
Muthukumar Dhanagopal
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i find out the occupied ports in the server machine. so that when we do the instalation, of some program or a server using java, I can change my port number dynamicaly.
 
Victor Htet
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what kind of server you are using. If you are using NT server, there is a free utility called Active Ports. you can download it free at www.ntutility.com.
You can view which ports are occupied by which processes.
 
Joel Peach
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Something else that works is the NT/2000 netstat command.
> netstat -a
This will dump all allocated/active sockets on all addresses.
There is also a good Linux portscan utility and graphical frontend, but for the life of me, I can't remember the name of it.
Best of luck!
-Joel
jpeach@traceris.com
 
Kyle Willkomm
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aren't you asking how to scan for the varios port's status in Java? Not with a third party utility? If not I would like to know anyhow if anyone knows of a way. And beyond that perhaps. What process and pid are running on that port? In case you have to use a particular port and can not find which process you need to kill to free up that port.
 
Glenn Murray
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it was the original author's intent to find out which ports were available from within the application---if not, it is certainly my question. When my users start the app I want the app to find out if, say, port 1099 (to pick a not quite random example) is already in use, and if so, to pick another one. I don't want my users to have to run nmap or netstat to find this out. I've run into conflicts with Netscapes Smart Update on port 1099, in fact.
Glenn
[This message has been edited by Glenn Murray (edited December 11, 2001).]
 
Barry Andrews
Ranch Hand
Posts: 529
C++ Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is a possible solution. You can run a batch program from the Java program that would run netstat and pipe the output to a text file. You could then read this file from the Java program to find out the ports in use. Or, maybe there is a way to bypass writing it to a file, and read it directly??? Does anyone know if this is possible? Hope this helps!
 
Shubhrajit Chatterjee
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a slow, but all java solution

However, I find the idea quite silly. If your server runs on a port which is decided dynamically then how on earth will the clients know where to connect ???

------------------
Shubhrajit :-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!