package mineplex.ddos; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Locale; import java.util.TimeZone; public class DDoSProtectionSwitcher { public static void main (String args[]) { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); PoolingClientConnectionManager connectionManager = new PoolingClientConnectionManager(schemeRegistry); connectionManager.setMaxTotal(200); connectionManager.setDefaultMaxPerRoute(20); HttpClient httpClient = new DefaultHttpClient(connectionManager); InputStream in = null; try { HttpGet request = new HttpGet("http://api.dnsmadeeasy.com/V2.0/dns/managed/962728/records/"); String timeStamp = getServerTime(); SecretKeySpec keySpec = new SecretKeySpec("8c9af8cc-d306-4df3-8de8-944deafa8239".getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(keySpec); byte[] hashBytes = mac.doFinal((timeStamp + "").getBytes()); Hex.encodeHexString(hashBytes); request.addHeader("x-dnsme-apiKey", "610e21ee-4250-4b55-b637-a1fcc3847850"); request.addHeader("x-dnsme-requestDate", timeStamp + ""); request.addHeader("x-dnsme-hmac", Hex.encodeHexString(hashBytes)); request.addHeader("Content-Type", "application/json"); HttpResponse response = httpClient.execute(request); if (response != null) { in = response.getEntity().getContent(); System.out.println(convertStreamToString(in)); } } catch (Exception ex) { System.out.println("JsonWebCall.Execute() Error:\n" + ex.getMessage()); for (StackTraceElement trace : ex.getStackTrace()) { System.out.println(trace); } } finally { httpClient.getConnectionManager().shutdown(); if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } } } private static String getServerTime() { Calendar calendar = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US); dateFormat.setTimeZone(TimeZone.getTimeZone("GMT")); return dateFormat.format(calendar.getTime()); } private static String convertStreamToString(InputStream is) { BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return sb.toString(); } }