dshrenik
asked on
Check status of a port
Please let me know how I can check if a port is available or not. If it is not available, i want to know what service is using it. I want to do this on both mac and windows.
Thanks!
Thanks!
if you use the dos telnet command and a blank dos window pops up the port is open..
telnet 127.0.1.1:portnumber
telnet 127.0.0.1:40
Also there are tons of opensource portscanners available if you want more details..
http://sourceforge.net/search/?type_of_search=soft&words=port+scanner
telnet 127.0.1.1:portnumber
telnet 127.0.0.1:40
Also there are tons of opensource portscanners available if you want more details..
http://sourceforge.net/search/?type_of_search=soft&words=port+scanner
netstat on windows:
http://security.fnal.gov/handouts/IdentifyingOpenPortsWinXP-2003.pdf
I guess Mac is like Unix they probably also have netstat. let's dig more
ASKER
I want to do it through java code. Thanks!
Java or Javascript?
ASKER
Java
If your goal is to find one port to use then trying telnet will be better
if your goal is to know which piorts are doing what then you need some utility to use
if your goal is to know which piorts are doing what then you need some utility to use
ASKER
I want to find out if a given port number is available. If it is not, I want to know what's using the port.
Thanks!
Thanks!
this is waht prints the open ports on Mac
"sudo lsof ..." (see caommand in there)
http://juretta.com/log/2007/08/08/list_open_ports_on_your_machine_mac_os_x_/
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You probably want to find options in these commands which will list you only your particular port which you are intesrested in.
So if you hget nothing - then your port is not used, otherwise you'll read from the output waht it is used for
So if you hget nothing - then your port is not used, otherwise you'll read from the output waht it is used for
ASKER
@hollecar:
Can you tell me how I can find out what service is using the port in case the port is unavailable. Thanks!
Can you tell me how I can find out what service is using the port in case the port is unavailable. Thanks!
Why do you need to know hwat service?
that's the difference - if you want to know if it is available - that;s mucvh easier inside java,
if you want to know who uses it - it is more dofficultb to do through pure java
that's the difference - if you want to know if it is available - that;s mucvh easier inside java,
if you want to know who uses it - it is more dofficultb to do through pure java
ASKER
I want to make sure the right service is using the port.
>>I want to make sure the right service is using the port.
You can only do that by getting a shell to the host on which the service is running and checking what process is involved
In windows and mac
netstat -o
This will give you the PID
MAC syntax may be different try looking at help on netstat
If you need this in Java also you could use a shell command
netstat -o
This will give you the PID
MAC syntax may be different try looking at help on netstat
If you need this in Java also you could use a shell command
Example...
final String cmd = "netstat -ano";
int pid = -1;
try {
// Run netstat
Process process = Runtime.getRuntime().exec(cmd);
} catch (Exception e) {
e.printStackTrace(System.err);
}
ASKER
@CEHJ:
Could you please elaborate a little more. If possible, please provide some sample code. Thanks!
Could you please elaborate a little more. If possible, please provide some sample code. Thanks!
WIndows
After you get the PID you can also use TASKLIST to get more details...
MAC
You may need a 3rd party tasklist utility
After you get the PID you can also use TASKLIST to get more details...
MAC
You may need a 3rd party tasklist utility
Here is a useful list of mac os X commands that you could use in a java shellcommand
http://ss64.com/osx/
http://ss64.com/osx/
Actually i retract that comment. You can only be sure by connecting to it and successfully implementing its protocol as a client.
btw, are you able to get a shell to the server?
btw, are you able to get a shell to the server?
Also you may need to test what o/s the program is on prior to executing any shell commands...Here is a sample I refer to occasionally....
public class OpertingSystemInfo
{
public static void main(String[] args)
{
String nameOS = "os.name";
String versionOS = "os.version";
String architectureOS = "os.arch";
System.out.println("\n The information about OS");
System.out.println("\nName of the OS: " +
System.getProperty(nameOS));
System.out.println("Version of the OS: " +
System.getProperty(versionOS));
System.out.println("Architecture of THe OS: " +
System.getProperty(architectureOS));
}
}
Not sure how that accepted solution is relevant to your question. Can you explain?
ASKER
The code tells me if a given port is available or nor. Right?
and then get the output into back to java and anlyze it.
And it would be pdifferent on Windows and Mac.
Let me dig what is the utility.