多个IPv4发送HTTP请求

时间:2017-01-27 18:48:07

标签: java http ipv4

我是java的网络方面的新手,我需要一些帮助。

我的ubuntu机器上的ifconfig: (我有3个我想要使用的IP)

ens18
          inet addr:1.123.123.123  Bcast:1.123.191.255  Mask:255.255.255.0

ens18:0
          inet addr:1.123.123.124  Bcast:1.123.191.255  Mask:255.255.255.0

ens18:1
          inet addr:1.123.123.125  Bcast:1.123.191.255  Mask:255.255.255.0

我希望能够通过每个请求发送HTTP请求,例如:

URL url = new URL("http://google.com");

Proxy p = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.123.123.123", 8080));
Proxy p2 = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.123.123.124", 8080));
Proxy p 3= new Proxy(Proxy.Type.HTTP, new InetSocketAddress("1.123.123.125", 8080));


HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(p);

int responseCode = connection.getResponseCode();

等...遍历机器上的所有IPv4

我已经在互联网上查找过,无法找到适用于我尝试做的任何代码。

1)如何在我的机器上找到所有IPv4 2)这是通过每个IP发送HTTP请求的正确代码吗?

谢谢

1 个答案:

答案 0 :(得分:0)

1

InetAddress[] allAddresses = InetAddress.getAllByName("localhost");
InetAddress[] ip4Addresses = Arrays.stream(allAddresses)
                                   .filter(address -> address.getHostAddress().indexOf("::") == -1)
                                   .toArray(InetAddress[]::new);
  1. 是的,这是您通过代理发送请求的方式