⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 简易的telnet操作java.txt

📁 简易的telnet操作java.rar
💻 TXT
字号:
/* @author javar*/
import java.net.*;
import java.io.*;
public class JTelnet
{   
    Socket sock; 
    public JTelnet(String h, int p)
    {   
        try 
        {       
            sock = new Socket(h, p);        
            new InputPipe(sock.getOutputStream()).start();      
            new OutputPipe(sock).start();   
        }   
        catch(IOException e)    
        {       
            System.out.println(e);      
            return; 
        }
    }
    public class InputPipe extends Thread
    {   
        DataInputStream is; 
        PrintStream     os;
        public InputPipe(OutputStream os)
        {   
            this.is = new DataInputStream(System.in);   
            this.os = new PrintStream(os);
        }
        public void run() 
        {   
            String line;    
            try     
            {       
                while(true)         
                {           
                    line = is.readLine();           
                    os.print(line);         
                    os.print("\r\n");           
                    os.flush();     
                }   
            }   
            catch(IOException e)    
            {       
                throw new RuntimeException(e.getMessage()); 
            }
        }
    }
    public class OutputPipe extends Thread 
    {   
        InputStream     in; 
        OutputStream    ot; 
        PrintStream     os;
        public OutputPipe(Socket sock)
        {   
            try 
            {       
                this.ot = sock.getOutputStream();       
                this.in = sock.getInputStream();        
                this.os = new PrintStream(System.out);  
            }   
            catch(IOException e)    
            {       
                System.out.println(e);  
            }
        }
        public void run()
        {
            String line;    
            int    i;   
            try 
            {       
                while(true)         
                {           
                    i = in.read();              
                    if (i == 255)           
                    {               
                        int i1 = in.read();                 
                        int i2 = in.read();             
                        tel_net(i1,i2);             
                    }           
                    else            
                    {               
                        os.print((char)i);              
                        os.flush();         
                    }       
                }   
            }   
            catch(IOException e)    
            {       
                throw new RuntimeException(e.getMessage()); 
            }
        }
        private void tel_net(int i1, int i2)
        {   
            int i = i1; 
            if (i == 253)   
            {       
                i = i2;          
                if (i == 1)  wont(i);       
                else if (i == 24) wont(i);      
                else if (i == 31) wont(i);      
                else if (i == 35) wont(i);      
                else if (i == 36) wont(i);      
                else if (i == 39) wont(i);  
            }
        }
        private void wont(int i)
        {   
            try     
            {       
                ot.write(255);      
                ot.write(252);      
                ot.write(i);    
            }   
            catch (IOException e)   
            {       
                System.out.println(e);  
            }
        }
    } 
    public static void main(String args[]) 
    {   
        String host = "bbs.jlu.edu.cn"; 
        int    port = 23;   
        new JTelnet(host, port);
    }
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -