Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 多个IPv4发送HTTP请求_Java_Http_Ipv4 - Fatal编程技术网

Java 多个IPv4发送HTTP请求

Java 多个IPv4发送HTTP请求,java,http,ipv4,Java,Http,Ipv4,我是java网络方面的新手,需要一些帮助 我的ubuntu计算机上的ifconfig: (我有3个要使用的IP) 我希望能够通过它们中的每一个发送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

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

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

我希望能够通过它们中的每一个发送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请求的正确代码吗

谢谢你

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

  • 我从中获得了IPv4,但我仍然不知道如何使用它作为代理<代码>代理p=新代理(Proxy.Type.DIRECT,新的InetSocketAddress(“1.123.123.123”,80));HttpsURLConnection connection=(HttpsURLConnection)url.openConnection(p)--我现在找到了获取IPv4的方法,但我不知道如何向他们请求您不知道如何向他们请求是什么意思,您只是在发布的代码中这样做?它不起作用。输出:
    java代理类型direct与地址不兼容。如果直接连接到资源(意味着不涉及代理)或留空(不要将任何内容传递给openConnection),则必须向该方法传递
    Proxy.NO_Proxy
    InetAddress[] allAddresses = InetAddress.getAllByName("localhost");
    InetAddress[] ip4Addresses = Arrays.stream(allAddresses)
                                       .filter(address -> address.getHostAddress().indexOf("::") == -1)
                                       .toArray(InetAddress[]::new);