December 11th, 2004 04:05 AM
Java port scanner problem
I have written a small port scnaner in Java. But I want to add some more functionality to it. Can anyone help me incorporate the following in my program:
1. List out the service that is listening on a particular port.
2. Close an open port (>1024, of course)
Help with example code would be very welcome.
December 11th, 2004 04:27 AM
I would have the portscanner generate some kind of output which can be read by another program running inparallel, or another function of the same program.
You could then use iptables, in conjuction with a wrapper script (well that's a linux solution, anyway), to act on that output and close the ports it deems necessary.
Of course, closing ports above 1024 may break random things like IM and p2p and gaming (insert snide Valve/Steam remark here).
In reality, I would think that a program which could decide for itself which ports to close and which ones are valid would require a lot of work, like inspecting state tables, checking sequence numbers, and so on. A human could probably do it a lot faster.
scan local host
close open port reported in output
But using Java to interact with a process on your machine with root priviliges mmight be difficult...
Government is like fire - a handy servant, but a dangerous master - George Washington
Government is not reason, it is not eloquence - it is force. - George Washington.
Join the UnError
December 11th, 2004 05:24 AM
Re: Java port scanner problem
Depending on your desired functionality, this could range from easy to difficult.
Originally posted here by benipegu
List out the service that is listening on a particular port.
The easy solution, nab a copy of /etc/services off of any nix distribution (attached in case you don't have access to one) and write a way to parse the file (probably want it in your own format at that point) and then pump out the entries when you list the ports.
Apart from an undesirable non-portable hack/wrapper scripts, I am not sure this could be done. I don't know for certain, but it is based on what I've run into in other areas in terms of controlling anything below the VM level. The VM operates in an isolated environment, it's tough to do things that exist outside this environment at all, let alone without wrappers.
Close an open port (>1024, of course)
The Nelson-Shepherd cutoff: The point at which you realise someone is an idiot while trying to help them.
\"Well as far as the spelling, I speak fluently both your native languages. Do you even can try spell mine ?\" -- Failed Insult
Is your whole family retarded, or did they just catch it from you?
December 16th, 2004 09:33 PM
Thnx guys. I have used a Hashtable. But ran into another problem. The scanner's lightning fast in Linux, but awfully slow in Windows. Can anyone tell me why?
December 17th, 2004 01:10 PM
chsh, I believe that with java you can write an external library in C++ that could access down to kernel level, then use the System.load(...) [it's something like that] command to load it in. Then you have access to any of the methods that you created in your C++ library.
I know you can do this with dll files, and I'm sure there must be a way to do it in *nix OSs.