Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // for use in applets when you can't set the ttl properly
- public static void clearDNSCache() {
- try {
- Field field = InetAddress.class.getDeclaredField("addressCache");
- field.setAccessible(true);
- Object obj = field.get(null);
- // synchronized on addressCache
- synchronized (obj) {
- Field cacheField = obj.getClass().getDeclaredField("cache");
- cacheField.setAccessible(true);
- Map cacheMap = (Map) cacheField.get(obj);
- cacheMap.clear();
- }
- System.err.println("Cleared DNS cache.");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
Add Comment
Please, Sign In to add comment