Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generating 16,777,216 values quickly?

807601Jun 3 2008 — edited Jun 6 2008
Well long story short I'm trying to build a list of valid IP addresses.

At work we use the a CLASS C which leaves the IP range from 10.0.0.0 - 10.255.255.255
which is equivalent to 256^3 = 16,777,216. Anyways long story short I work in a large building and I am attempting to develop this application that allows us to determine if any machines have been left on by pinging them. If the ping comes back than the machine was left on. The reason I want to do it in this fashion is because we are looking to expand and this allows me to scan the whole range of IP's no matter if we add computers or not.

Heres my code: The only problem is it takes several minutes. Is there a quicker way?
	private String[] buildIPList() {
		String []ips = null;
		int i = 0;
		int A = 10;
			for (int B = 0;B < 256; B++ ){
				for (int C = 0;C < 256; C++ ){
					for (int D = 0;D < 256; D++ ){
						ips[i] = (A+"."+B+"."+C+"."+D);
						i++;
					}
				}
			}
		return ips;
	}
Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 4 2008
Added on Jun 3 2008
41 comments
178 views