简体   繁体   中英

How can I know type of port activity using JAVA networking

I'm new at Java networking. I have made a programme in java which can show active ports of a web server. Here it is :

import java.net.Socket;
import java.util.Scanner;
import java.lang.Exception;
import java.lang.Thread;

class helper{
    public static void main(String []args){
        Scanner s= new Scanner(System.in);
        int port;
        System.out.print("Enter web url :");
        String url = s.next();
        for(port=0;port<65536;port++){
            helper2 h = new helper2(url,port);
            h.start();
        }
        s.close();
    }
}
class helper2 extends Thread{
    int port;
    String url;
    helper2(String url,int port){
        this.url=url;
        this.port=port;
    }
    private void getStatus(){
        try{
            Socket skt = new Socket(url,port);
            System.out.println(port);
            skt.close();
        }catch(Exception e){
            //Handle Exception here
        }
    }
    public void run(){
        getStatus();
    }

}

But now I want to print port type along with port number as if it is a TCP/IP, FTP, telnet or some other kind of port. I wanted to know if there is such function in java networking which returns the port type or is there some programme to do it. Also how to differentiate the difference type of ports? I mean not the programming point of view but the fundamental difference between them which provides them their identity and can be utilized in other programming language as a logic statement.

There should be something in the OS itself which returns what a port doing upon triggering.

For example: Suppose there are 65536 people (ports) are in a factory (machine or OS). At a time some of them are working (active) and others aren't. So if we ask them what's going on (port scanning like nmap) , the people not working will not say anything (return null or inactive signal) and the people who are working will say I'm doing this or that (tcp/udp, ssh, ftp, telnet).

So I want to catch up their response and make a programme for that. Would like to know how nmap actually does that ? How do we trigger a port and what is the response of that port ? How to differentiate between different types of port responses?

FTP and telnet are in the Application layer . You can check the Transport layer protocol changing the type of sockets, from TCP to UDP (right now you're only checking TCP). But in order to check the Application layer protocol you must know how each protocol works.

You can do a full port scan with nmap , it's a well known tool for network scanning.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM