Skip to content

Commit

Permalink
Corrections.
Browse files Browse the repository at this point in the history
  • Loading branch information
whoisxmlapi committed Jul 17, 2018
1 parent 047a18f commit 49208b1
Show file tree
Hide file tree
Showing 29 changed files with 695 additions and 508 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ via simple HTTP requests and returns results containing the IP address of the
primary domain (A record), DNS servers, mail servers (MX records) and more as
JSON/XML-encoded objects.

Here you'll find examples of using the API implemented in multiple languages.
Here you'll find examples of querying the API implemented in multiple
languages.

You'll need a
[WhoisXmlApi account](https://www.whoisxmlapi.com/user/create.php) to
authenticate.

This API also supports
[API key authentication](https://www.whoisxmlapi.com/user/management.php#api-key-management).

Please, refer to the
[DNS Lookup API User Guide](https://www.whoisxmlapi.com/dns-api-guide.php) for
info on input parameters, request/response formats, authentication
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions apikey/java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.whoisxmlapi</groupId>
<artifactId>dnslookup-apikey-sample</artifactId>
<version>1.0-SNAPSHOT</version>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>commons-httpclient</groupId>
Expand Down Expand Up @@ -41,5 +41,4 @@
</plugins>
</build>


</project>
127 changes: 81 additions & 46 deletions apikey/java/src/main/java/DnsLookupApiKeySample.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,46 @@
import org.json.JSONException;
import org.json.JSONObject;

public class DnsLookupApiKeySample {

private Logger logger = Logger.getLogger(DnsLookupApiKeySample.class.getName());

public static void main(String[]args) {
public class DnsLookupApiKeySample
{
private Logger logger =
Logger.getLogger(DnsLookupApiKeySample.class.getName());

public static void main(String[]args)
{
String checkType = "_all";
String domainName = "test.com";

String username = "Your dns lookup api username";
String apiKey = "Your dns lookup api apiKey";
String secretKey = "Your dns lookup api secretKey";
String apiKey = "Your dns lookup api key";
String secretKey = "Your dns lookup api secret key";

new DnsLookupApiKeySample().getDnsData(domainName, username, apiKey, secretKey);
new DnsLookupApiKeySample().getDnsData(
domainName, checkType, username, apiKey, secretKey);
}

private String executeURL(String url) {
private String executeURL(String url)
{
HttpClient c = new HttpClient();
System.out.println(url);

HttpMethod m = new GetMethod(url);
String res = null;

try {
c.executeMethod(m);

BufferedReader reader =
new BufferedReader(
new InputStreamReader(m.getResponseBodyAsStream()));
StringBuffer stringBuffer = new StringBuffer();
String str = "";
while((str = reader.readLine())!=null){
stringBuffer.append(str + "\n");
new InputStreamReader(m.getResponseBodyAsStream()));

StringBuilder stringBuffer = new StringBuilder();
String str;
while ((str = reader.readLine()) != null) {
stringBuffer.append(str);
stringBuffer.append("\n");
}

res = stringBuffer.toString();
} catch (Exception e) {
logger.log(Level.SEVERE, "Cannot get url", e);
Expand All @@ -53,66 +64,90 @@ private String executeURL(String url) {
return res;
}

public void getDnsData(String domainName, String username, String apiKey, String secretKey) {
String apiKeyAuthenticationRequest = generateApiKeyAuthenticationRequest(username, apiKey, secretKey);
if (apiKeyAuthenticationRequest == null) {
public void getDnsData(
String domainName,
String checkType,
String username,
String apiKey,
String secretKey
)
{
String apiKeyAuthRequest =
generateApiKeyAuthRequest(username, apiKey, secretKey);

if (apiKeyAuthRequest == null) {
return;
}

StringBuilder sb = new StringBuilder();
sb.append("http://www.whoisxmlapi.com/whoisserver/DNSService?");
sb.append(apiKeyAuthenticationRequest);
sb.append("&domainName=");
sb.append(domainName);
sb.append("&type=_all");
String url = sb.toString();

String result = executeURL(url);
if (result != null) {
logger.log(Level.INFO, "result: " + result);
try {
String url = "https://www.whoisxmlapi.com/whoisserver/DNSService"
+ "?" + apiKeyAuthRequest
+ "&domainName="
+ URLEncoder.encode(domainName, "UTF-8")
+ "&type="
+ URLEncoder.encode(checkType, "UTF-8");

String result = executeURL(url);

if (result != null)
logger.log(Level.INFO, "result: " + result);
}
catch (Exception e) {
logger.log(Level.SEVERE, "an error occurred", e);
}
}

private String generateApiKeyAuthenticationRequest(String username, String apiKey, String secretKey) {
private String generateApiKeyAuthRequest(
String username, String apiKey, String secretKey)
{
try {
long timestamp = System.currentTimeMillis();

String request = generateRequest(username, timestamp);
String digest = generateDigest(username, apiKey, secretKey, timestamp);

String requestURL = URLEncoder.encode(request, "UTF-8");
String digestURL = URLEncoder.encode(digest, "UTF-8");
String digest =
generateDigest(username, apiKey, secretKey, timestamp);

String apiKeyAuthenticationRequest = "requestObject="+requestURL+"&digest="+digestURL;
return apiKeyAuthenticationRequest;
return "requestObject=" + URLEncoder.encode(request, "UTF-8")
+ "&digest=" + URLEncoder.encode(digest, "UTF-8");
} catch (Exception e) {
logger.log(Level.SEVERE, "an error occurred", e);
}

return null;
}

private String generateRequest(String username, long timestamp) throws JSONException {
private String generateRequest(String username, long timestamp)
throws JSONException
{
JSONObject json = new JSONObject();
json.put("u", username);
json.put("t", timestamp);

String jsonStr = json.toString();
byte[] json64 = Base64.encodeBase64(jsonStr.getBytes());
String json64Str = new String(json64);
return json64Str;

return new String(json64);
}

private String generateDigest(String username, String apiKey, String secretKey, long timestamp) throws Exception {
StringBuilder sb = new StringBuilder();
sb.append(username);
sb.append(timestamp);
sb.append(apiKey);
private String generateDigest(
String username,
String apiKey,
String secretKey,
long timestamp
)
throws Exception
{
String sb = username + timestamp + apiKey;

SecretKeySpec secretKeySpec =
new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacMD5");

SecretKeySpec secretKeySpec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacMD5");
Mac mac = Mac.getInstance(secretKeySpec.getAlgorithm());
mac.init(secretKeySpec);

byte[] digestBytes = mac.doFinal(sb.toString().getBytes("UTF-8"));
String digest = new String(Hex.encodeHex(digestBytes));
return digest;
byte[] digestBytes = mac.doFinal(sb.getBytes("UTF-8"));

return new String(Hex.encodeHex(digestBytes));
}
}
66 changes: 43 additions & 23 deletions apikey/js/dns_lookup_apikey.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,45 @@
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<script type="text/javascript">
var domain = "google.com";
var key = "Your dns lookup api apiKey";
var secret = "Your dns lookup api secretKey";
var username = "Your dns lookup api username";
<!DOCTYPE html>
<html>
<head>
<title>DNS Lookup API jQuery Api Key Search Sample</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.js"></script>
<script type="text/javascript">

$(function () {
var time = (new Date()).getTime();
var req = btoa(unescape(
encodeURIComponent(JSON.stringify({t:time,u:username}))));
var digest = CryptoJS.HmacMD5(
username+time+key,secret).toString(CryptoJS.enc.Hex);
$.ajax({
url: "http://www.whoisxmlapi.com/whoisserver/DNSService",
dataType: "jsonp",
data: {type: "_all", requestObject: req, digest: digest,
domainName: domain, outputFormat: "JSON"},
complete: function(data) {
$("body").append("<pre>" + JSON.stringify(data, "",2) +"</pre>");
}
var url = "https://www.whoisxmlapi.com/whoisserver/DNSService";
var domain = "google.com";
var username = "Your dns lookup api username";
var key = "Your dns lookup api key";
var secret = "Your dns lookup api secret key";
var type = "_all";

$(function() {
var time = (new Date()).getTime();
var json = JSON.stringify({t: time, u: username});
var req = btoa(unescape(encodeURIComponent(json)));

var digest = CryptoJS.HmacMD5(username + time + key, secret)
.toString(CryptoJS.enc.Hex);
$.ajax(
{
url: url,
dataType: "jsonp",
data: {
type: type,
requestObject: req,
digest: digest,
domainName: domain,
outputFormat: "JSON"
},
complete: function(data) {
$("body").append(
"<pre>" + JSON.stringify(data,null,2) + "</pre>");
}
}
);
});
});
</script>

</script>
</head>
<body></body>
</html>
28 changes: 14 additions & 14 deletions apikey/net/ApiKeyDnsApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiKeyDnsApi", "ApiKeyDnsApi\ApiKeyDnsApi.csproj", "{237C394F-02AB-4688-A382-C69B283F4FFA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiKeyDnsApi", "ApiKeyDnsApi\ApiKeyDnsApi.csproj", "{27F86D29-6B8D-40D1-A991-DAC12F93F234}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{237C394F-02AB-4688-A382-C69B283F4FFA}.Debug|x86.ActiveCfg = Debug|x86
{237C394F-02AB-4688-A382-C69B283F4FFA}.Debug|x86.Build.0 = Debug|x86
{237C394F-02AB-4688-A382-C69B283F4FFA}.Release|x86.ActiveCfg = Release|x86
{237C394F-02AB-4688-A382-C69B283F4FFA}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{27F86D29-6B8D-40D1-A991-DAC12F93F234}.Debug|x86.ActiveCfg = Debug|x86
{27F86D29-6B8D-40D1-A991-DAC12F93F234}.Debug|x86.Build.0 = Debug|x86
{27F86D29-6B8D-40D1-A991-DAC12F93F234}.Release|x86.ActiveCfg = Release|x86
{27F86D29-6B8D-40D1-A991-DAC12F93F234}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading

0 comments on commit 49208b1

Please sign in to comment.