aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes Finding the Occupied ports in a Server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Finding the Occupied ports in a Server" Watch "Finding the Occupied ports in a Server" New topic
Author

Finding the Occupied ports in a Server

Muthukumar Dhanagopal
Greenhorn

Joined: Nov 20, 2001
Posts: 1
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

Joined: Apr 09, 2000
Posts: 70
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.


SCJP,SCWCD,SCEA,SCDJWS
Joel Peach
Greenhorn

Joined: Oct 12, 2001
Posts: 19
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

Joined: Sep 10, 2001
Posts: 44
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

Joined: Dec 07, 2001
Posts: 74
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).]


Glenn Murray
Author of Yo Soy Una Vaca De Hoy
Barry Andrews
Ranch Hand

Joined: Sep 05, 2000
Posts: 523

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

Joined: Aug 23, 2001
Posts: 356
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 :-)


Shubhrajit
 
 
subject: Finding the Occupied ports in a Server
 
Threads others viewed
Session conflict with servers on the same IP and different ports
problem opening port 900 on mac os x
Stop ports from remote program
Mysql jdbc connection takes lot of time
Port scanning Vista
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture