Domanda

I have recently built a port scanner using Java, it is for my university course (just so you know I'm not doing it for malicious reasons). Now we have been assigned to make it recognise which service is running on each port that is listening, I believe that each port will send a response header when it an application tries to connect to it, and I think that from this header it is possible to understand which application is running on it, unless it has been manually overridden. I am struggling to retrieve this header, and even then I am unsure what to actually do with it. I am sorry this is such a broad question, I am new to programming altogether. Any links or information you could share with me would be much appreciated. I did look through other questions but couldn't see one similar to my problem, I'm sorry if I missed it.

Thanks in Advance.

      public static void main(String[] args) {


    Socket socket;
    String message="";
    try {

        socket = new Socket();
        socket.connect(new InetSocketAddress("localhost", 3306),1000);
        BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        if (br.readLine()!=null){
             message += br.readLine();
             if (message!=null){
                    System.out.println(message);
                }
        }
È stato utile?

Soluzione

Now we have been assigned to make it recognise which service is running on each port that is listening

I don't believe your task is computationally feasible, unless you are allowed to lookup /etc/services.

I believe that each port will send a response header when it an application tries to connect to it

No. Telnet and HTTP for example send nothing until a request is received.

I am sorry this is such a broad question

It's not your fault, it's the fault of the assignment, unless you have misunderstood it or misquoted it here.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top