用socket实现代理的样子的各种方式:socket实现方式,telnet 实现方式 ,http proxy 实现方式
来源:互联网 发布:金三税个人所得税软件 编辑:程序博客网 时间:2024/04/29 09:34
1.socket实现方式:
2.telnet 实现方式
这个要加个jar包: commons-net-2.0.jar
3.http proxy 实现方式
- public class TestMonitor {
- public static void main(String[] args) throws IOException {
- Socket socket = null;
- // PrintWriter out = null;
- BufferedReader in = null;
- PrintStream ops= null;
- try {
- socket = new Socket(args[0], 4444);//参数为服务器的ip地址
- ops=new PrintStream(socket.getOutputStream());
- ops.println(args[1]); // 参数是发送到服务器上的请求信息
- ops.flush();
- // out = new PrintWriter(socket.getOutputStream(), true);
- in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- } catch (UnknownHostException e) {
- System.err.println("Don't know about host:" + args[0]);
- System.exit(1);
- } catch (IOException e) {
- System.err.println("Couldn't get I/O for the connection to: taranis.");
- System.exit(1);
- }
- BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
- String fromServer;
- // String fromUser = stdIn.readLine();
- // System.out.println("Client: " + fromUser);
- // out.println(fromUser);
- while ((fromServer = in.readLine()) != null) {
- System.out.println("Server: " + fromServer);
- if (fromServer.equals("Bye."))
- break;
- String fromUser = stdIn.readLine();
- if (fromUser != null) {
- System.out.println("Client: " + fromUser);
- ops.println(fromUser);
- }
- }
- ops.close();
- in.close();
- stdIn.close();
- socket.close();
- }
- }
public class TestMonitor {public static void main(String[] args) throws IOException { Socket socket = null; // PrintWriter out = null; BufferedReader in = null; PrintStream ops= null; try { socket = new Socket(args[0], 4444);//参数为服务器的ip地址 ops=new PrintStream(socket.getOutputStream()); ops.println(args[1]); // 参数是发送到服务器上的请求信息 ops.flush(); // out = new PrintWriter(socket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); } catch (UnknownHostException e) { System.err.println("Don't know about host:" + args[0]); System.exit(1); } catch (IOException e) { System.err.println("Couldn't get I/O for the connection to: taranis."); System.exit(1); } BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in)); String fromServer;// String fromUser = stdIn.readLine();// System.out.println("Client: " + fromUser);// out.println(fromUser); while ((fromServer = in.readLine()) != null) { System.out.println("Server: " + fromServer); if (fromServer.equals("Bye.")) break; String fromUser = stdIn.readLine(); if (fromUser != null) { System.out.println("Client: " + fromUser); ops.println(fromUser); } } ops.close(); in.close(); stdIn.close(); socket.close(); }}
2.telnet 实现方式
这个要加个jar包: commons-net-2.0.jar
- public class TestTelnet {
- /**
- * @param args
- */
- public static void main(String[] args) {
- TelnetClient tc=new TelnetClient();
- PrintStream ops= null;
- BufferedReader in = null;
- try {
- tc.connect("172.16.100.87", 4444);//连接的服务器和端口
- System.out.println("test cennection:"+tc.isConnected());
- ops=new PrintStream(tc.getOutputStream());
- ops.println("/refreshapps"); // 是发送到服务器上的请求信息
- ops.flush();
- in = new BufferedReader(new InputStreamReader(tc.getInputStream()));
- // System.out.println( "AAA"+in.readLine());
- char[] bs=new char[256];
- int i=0;
- while((i=in.read(bs))>-1){
- String str=null;
- if(i==256){
- str=new String(bs);
- }else{
- char[] bs2=new char[i];
- for(int j=0;j<i;j++)
- {
- bs2[j]=bs[j];
- }
- str=new String(bs2);
- }
- System.out.println(str);
- }
- } catch (SocketException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
public class TestTelnet {/** * @param args */public static void main(String[] args) {TelnetClient tc=new TelnetClient();PrintStream ops= null; BufferedReader in = null;try {tc.connect("172.16.100.87", 4444);//连接的服务器和端口System.out.println("test cennection:"+tc.isConnected());ops=new PrintStream(tc.getOutputStream());ops.println("/refreshapps"); // 是发送到服务器上的请求信息ops.flush(); in = new BufferedReader(new InputStreamReader(tc.getInputStream())); // System.out.println( "AAA"+in.readLine());char[] bs=new char[256];int i=0;while((i=in.read(bs))>-1){String str=null;if(i==256){str=new String(bs);}else{char[] bs2=new char[i];for(int j=0;j<i;j++){bs2[j]=bs[j];}str=new String(bs2);}System.out.println(str);}} catch (SocketException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}
3.http proxy 实现方式
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.net.URLConnection;
- import java.util.Properties;
- public class TestProxy {
- /**
- * @param args
- * @throws IOException
- */
- public static void main(String[] args) throws IOException {
- // String strUrl="http://blog.csdn.net/cqq/";
- // URL url = new URL(strUrl);
- URL url = new URL("http", "172.16.100.87", 4444, "");//所请求服务器的ip地址和端口
- URLConnection conn = url.openConnection();
- String strProxy = "172.16.10.133";//代理服务器的ip
- String strPort = "4444";//端口
- Properties systemProperties = System.getProperties();
- systemProperties.setProperty("http.proxyHost", strProxy);
- systemProperties.setProperty("http.proxyPort", strPort);
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn
- .getInputStream()));
- String ss = null;
- while ((ss = rd.readLine()) != null) {
- System.out.println(ss);
- }
- rd.close();
- }
- }
- 用socket实现代理的样子的各种方式:socket实现方式,telnet 实现方式 ,http proxy 实现方式
- socket的实现方式
- 代理的另一种实现方式
- java代理的实现方式
- HTTP实现断点续传的方式
- C语言以epoll方式实现的简单socket实例
- 进度条实现---各种方式
- spring事务的代理方式的实现
- socket连接联网查询客户端实现方式
- C语言select方式实现socket实例
- Socket 使用select()非阻塞方式实现
- 代理的四种实现方式
- 关于SearchaBar的bookMarks(代理方式实现)
- 两种动态代理的实现方式
- java代理模式的实现方式
- 动态代理的两种实现方式
- Nginx实现websocket代理的方式
- 实现动态代理的两种方式
- VC2005从开发MFC ActiveX ocx控件到发布到.net网站的全部过程
- js时按钮不能使用详解
- 我思故我在系列—数据结构面试NO.20题将一串字符串转为整数(题目搜集整理者JVLY,非常感谢!!)
- http://acm.nyist.net/JudgeOnline/problem.php?pid=434
- Eclipse基本使用1
- 用socket实现代理的样子的各种方式:socket实现方式,telnet 实现方式 ,http proxy 实现方式
- Socket编程(一)
- Android 的用户层 uevent处理机制
- JavaScript学习笔记(一)——基本语法
- 《Oracle编程艺术》学习笔记(22)-表类型
- OK6410裸机调试(使用串口,不需要使用JLINK)
- 编程匠艺(一)善于防守——健壮代码的防御性编程技巧
- jsp中文输入,提交后显示乱码
- Java 线程的停止