🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #23186

�ȼ�

#23186
From: liuyidaojian
Date: Mon, 11 Aug 2003 04:45
122 lines
4083 bytes
����һ��telnet�ͻ��˳��� 
 
 
����vc����д��һ�����������յ���login:,Ȼ���ˣ��û���Ȼ�󣬾����ղ�����pas
sword, 
�յ�����һ��255 255 255 255 255 255 255 255�������� 
��֪����ô�����飬˭����ע��һ������ij���� 
��� 
import java.net.*; 
import java.io.*; 
 
public class T2 { 
	Socket serverSocket;  
	public OutputStream serverOutput�� 
	public BufferedInputStream serverInput;  
	static final int DEFAULT_TELNET_PORT = 23;  
 
 
	public void openConnection(String host,int port) 
		throws IOException,UnknownHostException 
	{ 
		serverSocket = new Socket(host, port); 
		serverOutput = serverSocket.getOutputStream(); 
		serverInput = new 
			BufferedInputStream(serverSocket.getInputStream()); 
		if (port == DEFAULT_TELNET_PORT){ 
			negotiation(serverInput, serverOutput); 
		} 
	} 
 
		public void main_proc() 
		throws IOException 
	{ 
		try { 
						StreamConnector stdin_to_socket = 
				new StreamConnector(System.in, serverOutput); 
			StreamConnector socket_to_stdout = 
				new StreamConnector(serverInput, System.out); 
			 
			Thread input_thread = new Thread(stdin_to_socket); 
			Thread output_thread = new Thread(socket_to_stdout); 
	 
			input_thread.start(); 
			output_thread.start(); 
		} 
		catch(Exception e){ 
			System.err.print(e); 
			System.exit(1); 
		} 
	} 
 
	 
	static final byte IAC = (byte) 255; 
	static final byte DONT = (byte) 254; 
	static final byte DO = (byte) 253; 
	static final byte WONT = (byte) 252; 
	static final byte WILL = (byte) 251; 
 
	 
	static void negotiation(BufferedInputStream in,OutputStream out) 
		throws IOException 
	{ 
		byte[] buff = new byte[3];//�R�}���h��M�p�z�� 
		while(true) { 
			in.mark(buff.length); 
			if (in.available() >= buff.length) { 
				in.read(buff); 
				if (buff[0] != IAC){// �l�S�V�G�[�V�����I�� 
					in.reset(); 
					return; 
				} else if (buff[1] == DO) {// DO�R�}���h�ɑ΂��Ắc 
					buff[1] = WONT; // WON'T�ŕԓ����܂� 
					out.write(buff); 
				} 
			} 
		} 
	} 
 
	// main���\�b�h 
	// TCP�R�l�N�V�������J���ď������J�n���܂� 
	public static void main(String[] arg){ 
		try { 
                        String x="172.18.36.92"; 
			T2 t = null; 
			t = new T2(); 
			t.openConnection( x, Integer.parseInt("23") ); 
			t.main_proc(); 
		}catch(Exception e){ 
			e.printStackTrace(); 
			System.exit(1); 
		} 
	} 
} 
 
// class StreamConnector implements Runnable { 
	InputStream src = null; 
	OutputStream dist = null; 
		public StreamConnector(InputStream in, OutputStream out){ 
		src = in; 
		dist = out; 
	} 
 
		public void run(){ 
		byte[] buff = new byte[1024]; 
		while (true) { 
			try { 
				int n = src.read(buff); 
				if (n > 0) 
					dist.write(buff, 0, n); 
			} 
			catch(Exception e){ 
				e.printStackTrace(); 
				System.err.print(e); 
				System.exit(1); 
			} 
		} 
	} 
} 

--

�� ��Դ:���㽭��ѧ���ɰٴ�վ http://bbs.zju.edu.cn [FROM: liuyidaojian]
Technical Details
Message-ID: <47bliY$9aT@bbs.zju.edu.cn>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!pln-e!extra.newsguy.com!lotsanews.com!nf3.bellglobal.com!snoopy.risq.qc.ca!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.happynet.org!ZJUBBS

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: f6cb0,3186691791dbca90,start
X-Google-Attributes: gidf6cb0,public
X-Google-ArrivalTime: 2003-08-10 21:48:42 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!pln-e!extra.newsguy.com!lotsanews.com!nf3.bellglobal.com!snoopy.risq.qc.ca!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!maily.cic.tsinghua.edu.cn!news.happynet.org!ZJUBBS
From: liuyidaojian.bbs@bbs.zju.edu.cn (liuyidaojian)
Newsgroups: cn.bbs.comp.lang.java
Subject: �ȼ�
Date: 11 Aug 2003 04:45:22 GMT
Organization: �㽭��ѧ���ɰٴ�
Message-ID: <47bliY$9aT@bbs.zju.edu.cn>
X-Filename: Java/M.1060577122.A
Lines: 122