1

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.

cantread
  • 405
  • 1
  • 7
  • 14
  • Can you post the URLs you were testing? – betteroutthanin Feb 26 '14 at 22:24
  • http://www.3dbrickpavingandnaturalstone.com/ http://www.320ranch.com/ http://a1carpetandtile.com/ http://www.adoberesort.com/ http://www.advancedlightandsound.com/ http://www.thealhonnaresort.com/ http://www.andersoncertified.com/ http://www.cabinsoftheblackhills.com/ http://www.banffcariboulodge.com/ http://www.rockymountainresort.com/ http://www.berrycreekcabins.com/ http://www.birchcliff.com/ http://www.blackbutteranch.com/ http://blueharborresort.com/ http://www.orcasislandboardwalk.com/ http://www.buffalocountyoutfitters.com/ Just a few – cantread Feb 26 '14 at 22:25

1 Answers1

1

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);

}
betteroutthanin
  • 7,148
  • 8
  • 29
  • 48