fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.net.*;
  4.  
  5. class Main
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9.  
  10. InetAddress from = InetAddress.getByName("1.2.3.4");
  11. InetAddress to = InetAddress.getByName("1.2.5.6");
  12. byte[] partsTo = to.getAddress();
  13. for (;;) {
  14. System.out.print(from+" - ");
  15. byte[] parts = from.getAddress();
  16. boolean sameUpperPart = true;
  17. for (int i = 0 ; sameUpperPart && i < parts.length-1 ; i++) {
  18. sameUpperPart &= (partsTo[i] == parts[i]);
  19. }
  20. if (sameUpperPart) {
  21. System.out.println(to);
  22. break;
  23. }
  24. int last = parts.length-1;
  25. parts[last] = (byte)0xFF;
  26. System.out.println(InetAddress.getByAddress(parts));
  27. parts[last] = 0x00;
  28. for (int i = last-1 ; i >= 0 ; i--) {
  29. if (++parts[i] != 0) {
  30. break;
  31. }
  32. }
  33. from = InetAddress.getByAddress(parts);
  34. }
  35.  
  36.  
  37. }
  38. }
Success #stdin #stdout 0.03s 245696KB
stdin
Standard input is empty
stdout
/1.2.3.4 - /1.2.3.255
/1.2.4.0 - /1.2.4.255
/1.2.5.0 - /1.2.5.6