[英]Multiple IPv4 sending HTTP requests
I'm new to the networking side of java and I need some help. 我是Java网络方面的新手,我需要一些帮助。
My ifconfig on my ubuntu machine: (I have 3 IPs I want to use) 我的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
I want to be able to send HTTP request through each of them, example: 我希望能够通过它们中的每个发送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();
etc... loop through all IPv4 on machine 等等...遍历机器上的所有IPv4
I have looked on the internet and can't find any code that will work for what I'm trying to do. 我在互联网上看过,找不到任何适用于我正在尝试执行的代码。
1) How do I find all IPv4 on my machine 2) Is that the correct code to send HTTP request through each IP? 1)如何在我的计算机上找到所有IPv4?2)通过每个IP发送HTTP请求的代码是否正确?
Thank you 谢谢
1. 1。
InetAddress[] allAddresses = InetAddress.getAllByName("localhost");
InetAddress[] ip4Addresses = Arrays.stream(allAddresses)
.filter(address -> address.getHostAddress().indexOf("::") == -1)
.toArray(InetAddress[]::new);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.