问题
I want to be able to get whois data (and idn domains too) by client-side javascript. Is it possible? Maybe some free REST-like WhoIs service exists?
回答1:
Try using http://whoisxmlapi.com service.
The service URL: http://www.whoisxmlapi.com/whoisserver/WhoisService
You need to specify outputFormat=json
and domainName=insert_domain_here
parameters..
Example URL: http://www.whoisxmlapi.com/whoisserver/WhoisService?outputFormat=json&domainName=stackoverflow.com.
Example code (using jQuery to simplify AJAX communication):
$.ajax({
url: 'http://www.whoisxmlapi.com/whoisserver/WhoisService',
dataType: 'jsonp',
data: {
domainName: 'stackoverflow.com',
outputFormat: 'json'
},
success: function(data) {
console.log(data.WhoisRecord);
}
});
HERE is the working code.
Update:
The service mentioned above is not free, but there are several free whois services that are providing HTML output and by using YQL you can retrieve the HTML as a JS. See THIS answer for more details.
Example (using jQuery & jquery.xdomainajax):
var domain = 'stackoverflow.com';
$.ajax({
url: 'http://whois.webhosting.info/' + domain,
type: 'GET',
success: function(res) {
// using jQuery to find table with class "body_text" and appending it to a page
$(res.responseText).find('table.body_text').appendTo('body');
}
});
HERE is the working code.
You need to have a look at the structure of the HTML document and select, process and display the data you are interested in. The example is just printing whole table without any processing.
回答2:
What you can do if you have exec() enabled in php is create a php file with the following:
exec('whois domain.com');
and then create aa .ajax() request to the php script where you pass the domain name and output it.
回答3:
i'm also trying to find out a free whois provider with JSON output, couldn't find one. But, there are WHOIS windows client provided by Microsoft and like someone mentioned above, we can use PHP/cgi to get the details.
I'm not sure whether there's any WHOIS lookup/query provider gives JSON output at free cost.
BTW, i just found this phpWhois from sourceforge.net, would be a good starting point to use whois from the server. This is the library used by RoboWhois / RubyWhois provider as well.
回答4:
An npm package called node-whois did the job for me. It's server side JS, not client side, but perhaps this will help someone.
来源:https://stackoverflow.com/questions/8435678/whois-with-javascript