I'm trying to go through a list of URL's and grab their IP but what I'm noticing is sometimes it will get hung up on a website and never move on and other times it will skip a bunch of websites. Does anyone know what's causing this?
for (String site : sites) {
try {
address = InetAddress.getByName(new URL(site).getHost()).getHostAddress();
} catch (Exception e) {
System.out.println(e);
}
IPList.put(address, site);
publish(site);
}
EDIT: I've narrowed the problem down to the publish method. It seems like it's finishing the for loop before it has a chance to publish everything and then it just stops...
EDIT2: Figured it out, small mistake on my end. Thanks.
Try this:
private ArrayList<String> ips = new ArrayList<String>();
for (String site : sites) {
try {
address = InetAddress.getByName(new URL(site).getHost());
} catch (Exception e) {
System.out.println(e);
}
String ip = address.getHostAddress();
ips.add(ip);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.