简体   繁体   中英

How to find out client is connecting to my server through telnet?

I'm writing a ServerSocket in java. I want to send some special content to client connecting to me through telnet . I want to send other content if he/she connects through Browser and etc. Is there any way to find out that user is connecting to me with telnet ?

My code :

public void handleConnection(Socket socket) throws IOException {
    String author = "Ehsan Akbari";
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
    if(checkoutClientType(socket)=="telnet")
        out.println("You are connecting through telnet :\)");
    else
        out.println("You are not connecting through telnet :|");
}

What should be the definition of checkoutClientType(Socket s); ?

You cannot tell what program is on the other side of a socket by examining the socket itself. There is no test or operation you can perform on the socket that will distinguish the client program.

The only hope is to examine the data being transmitted to see if it matches an expected pattern, but for that you have to have some data transmitted. It might be possible to tell if the remote is telnet if you were to send a Telnet Protocol command such as AYT (Are You There), but that would probably not sit well with a different client such as a browser.

If you were able to proxy the data between the client and a handling process or thread and examine it you might be able to eventually determine if it was Telnet, but probably not, and probably not immediately.

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