java网络访问指定出口ip

java网络访问指定出口ip

Table of Contents

1 socket

能够在Socket构造函数中指定使用的本地ip,如:
java

Socket socket = new Socket("127.0.0.1", 12345, InetAddress.getByAddress(new byte[] {
                new Integer(10).byteValue(),
                new Integer(211).byteValue(),
                new Integer(55).byteValue(),
                new Integer(2).byteValue(),
        }), 1234);

2 apache httpclient

经过HttpClient设置便可,以下:
sql

byte b[] = new byte[4];
b[0] = new Integer(10).byteValue();
b[1] = new Integer(211).byteValue();
b[2] = new Integer(55).byteValue();
b[3] = new Integer(2).byteValue();

CloseableHttpResponse response = null;
CloseableHttpClient httpclient = HttpClients.createDefault();

HttpGet httpget = new HttpGet("http://localhost:8080/TestServlet");
httpget.setConfig(RequestConfig.custom()
        .setLocalAddress(InetAddress.getByAddress(b))
        .build());

Author: galaxyapache

Created: 2016-08-31 Wed 17:11bash

Emacs 24.5.6 (Org mode 8.2.10)网络

Validatesocket

相关文章
相关标签/搜索