Results 1 to 5 of 5

Thread: Java port scanner problem

  1. #1
    Junior Member
    Join Date
    Dec 2004

    Exclamation 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.


  2. #2
    Senior Member
    Join Date
    Oct 2002
    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
    generate output
    read output
    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 community!

  3. #3
    Senior Member
    Join Date
    Nov 2001

    Re: Java port scanner problem

    Originally posted here by benipegu
    List out the service that is listening on a particular port.
    Depending on your desired functionality, this could range from easy to difficult.
    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.

    Close an open port (>1024, of course)
    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.
    Chris Shepherd
    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?

  4. #4
    Junior Member
    Join Date
    Dec 2004
    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?

  5. #5
    Custom User
    Join Date
    Oct 2001
    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts