GenuineSounds

Host file generator.

May 30th, 2014
401
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.74 KB | None | 0 0
  1. package com.genuinevm.src;
  2.  
  3. import java.net.InetAddress;
  4. import java.net.URL;
  5. import java.util.ArrayList;
  6. import java.util.Collections;
  7. import java.util.Comparator;
  8. import java.util.List;
  9. import java.util.SortedMap;
  10. import java.util.TreeMap;
  11.  
  12. // Run this from home or any other computer with no dns restriction.
  13. // The output is suitable for a Host file, this overrides the dns lookup.
  14. // This will hopefully unblock the websites that are blocked by most content blockers.
  15. public class Main {
  16.  
  17.     public static Comparator<? super String> comparator = (k1, k2) -> {
  18.         String[] str1 = k1.split("\\.");
  19.         String[] str2 = k2.split("\\.");
  20.         int[] is1 = new int[] {
  21.             Integer.parseInt(str1[0], 10),
  22.             Integer.parseInt(str1[1], 10),
  23.             Integer.parseInt(str1[2], 10),
  24.             Integer.parseInt(str1[3], 10)
  25.         };
  26.         int[] is2 = new int[] {
  27.             Integer.parseInt(str2[0], 10),
  28.             Integer.parseInt(str2[1], 10),
  29.             Integer.parseInt(str2[2], 10),
  30.             Integer.parseInt(str2[3], 10)
  31.         };
  32.         for (int i = 0; i < 4; i++) {
  33.             int i1 = is1[i];
  34.             int i2 = is2[i];
  35.             if (i1 == i2)
  36.                 continue;
  37.             if (i1 < i2)
  38.                 return -1;
  39.             else
  40.                 return 1;
  41.         }
  42.         return 0;
  43.     };
  44.  
  45.     public static List<String> urlList = new ArrayList<>();
  46.  
  47.     public static SortedMap<String, List<String>> map =
  48.             Collections.synchronizedSortedMap(new TreeMap<String, List<String>>(comparator));
  49.  
  50.     // This example comes with most of the steam dns look-ups. You can
  51.     public static void main(String[] args) {
  52.         // Add your websites here. You can delete these examples if you want.
  53.         urlList.add("steampowered.com");
  54.         urlList.add("valvesoftware.com");
  55.         urlList.add("store.steampowered.com");
  56.         urlList.add("cdn.store.steampowered.com");
  57.         urlList.add("media.steampowered.com");
  58.         urlList.add("storefront.steampowered.com");
  59.         urlList.add("cdn.steamcommunity.com");
  60.         urlList.add("support.steampowered.com");
  61.         urlList.add("translation.steampowered.com");
  62.         urlList.add("store.valvesoftware.com");
  63.         urlList.add("source.valvesoftware.com");
  64.         urlList.add("steamcommunity.com");
  65.         urlList.add("api.steampowered.com");
  66.         urlList.add("cafe.steampowered.com");
  67.         urlList.add("client-download.steampowered.com");
  68.         for (int i = 0; i < 100; i++) {
  69.             urlList.add("media" + i + ".steampowered.com");
  70.             urlList.add("cdn" + i + ".store.steampowered.com");
  71.             urlList.add("cdn" + i + ".steamcommunity.com");
  72.             urlList.add("cloud-" + i + ".steampowered.com");
  73.             urlList.add("content" + i + ".steampowered.com");
  74.         }
  75.         for (int i = 0; i < 500; i++) {
  76.             urlList.add("valve" + Integer.toString(i, 10) + ".cs.steampowered.com");
  77.         }
  78.         // Do not edit below this line. Unless you really want to.
  79.         urlList.stream().parallel().forEach(Main::getIP);
  80.         map.forEach(Main::output);
  81.     }
  82.  
  83.     public static void getIP(String s) {
  84.         try {
  85.             InetAddress address = InetAddress.getByName(new URL("http://" + s).getHost());
  86.             String key = address.getHostAddress();
  87.             synchronized (map) {
  88.                 map.putIfAbsent(key, new ArrayList<>());
  89.                 map.get(key).add(s);
  90.                 if (s.replaceAll("[^.]", "").length() <= 1)
  91.                     map.get(key).add("www." + s);
  92.             }
  93.         }
  94.         catch (Exception e) {}
  95.     }
  96.  
  97.     public static void output(String k, List<String> v) {
  98.         Collections.sort(v, (s1, s2) -> s1.compareToIgnoreCase(s2));
  99.         String line = "";
  100.         for (int i = 0; i < v.size(); i++) {
  101.             String tmp = v.get(i);
  102.             line = line + buffer(tmp, " ", ((i * 36) - line.length() + tmp.length()), true);
  103.         }
  104.         System.out.println(buffer(k, " ", 18, false) + line);
  105.     }
  106.  
  107.     public static String buffer(String input, String buffer, int max, boolean leading) {
  108.         while (input.length() < max) {
  109.             if (input.length() >= max)
  110.                 break;
  111.             if (leading)
  112.                 input = buffer + input;
  113.             else
  114.                 input = input + buffer;
  115.         }
  116.         return input;
  117.     }
  118. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment