0

How can I get information about a domain name (such as owner or server details) using PHP or Python code? I'd like to avoid using any 3rd party web site.

Is this possible?

1
  • Are just excluding 3rd party webtools? whois db, DNS are by definition third party services. And fingerprinting serverdetails is a hard problem to tackle on your own without use of third party libraries. Commented Mar 21, 2014 at 9:18

3 Answers 3

2

You can base yourself on the following whois script: http://www.phpeasycode.com/whois/

Here's an online demo.

The script first checks for the right whois server and then opens a socket on port 43. Here's a simpliefied query function based on the code from the demo above.

Each TLD has its own whois server. You can find a complete list here : http://www.iana.org/domains/root/db/ and http://www.whois365.com/en/listtld/

<?php
$whoisserver = "whois.pir.org";
$domain = "example.org";
$port = 43;
$timeout = 10;
$fp = @fsockopen($whoisserver, $port, $errno, $errstr, $timeout) or die("Socket Error " . $errno . " - " . $errstr);
fputs($fp, $domain . "\r\n");
$out = "";
while(!feof($fp)){
    $out .= fgets($fp);
}
fclose($fp);

$res = "";
if((strpos(strtolower($out), "error") === FALSE) && (strpos(strtolower($out), "not allocated") === FALSE)) {
    $rows = explode("\n", $out);
    foreach($rows as $row) {
        $row = trim($row);
        if(($row != '') && ($row{0} != '#') && ($row{0} != '%')) {
            $res .= $row."\n";
        }
    }
}
print $res;
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks boss, there is script also.. phpeasycode.com/count.php?target=whois/whois.zip
Just a link?... You missed a chance of making a real answer. The OP is from url to domain & server details. With little effort you can show how PHP shines in parsing the hostname from the url and make a start investigating server details.
Thanks, I didn't want to link directly to the download to give credit to the author.
I'm sorry, I'm warming up today. I'll edit the question to include some information as how the script works.
Answering questions is nice. Links are great. Giving credit where credit is due, even better. I'm not saying you should write a book or whole script in the answer. But the web is already full of forums with short First Post links that have rotted. With little extra effort you'll have something that survives the tests of time somewhat longer.
|
1

First make your live easier:

pip install python-whois
pip install requests

Then do something like:

>>> import requests
>>> import urlparse
>>> import whois
>>> url = 'http://docs.python.org/3/'
>>> requests.head(url).headers['server']
'Apache/2.2.22 (Debian)'
>>> hostname = urlparse.urlparse(url).netloc
>>> print whois.whois(hostname)
creation_date: 1995-03-27 05:00:00
domain_name: PYTHON.ORG
emails: ['[email protected]', '[email protected]', '[email protected]']
expiration_date: []
name_servers: ['NS3.P11.DYNECT.NET', 'NS1.P11.DYNECT.NET', 'NS2.P11.DYNECT.NET', 'NS4.P11.DYNECT.NET', '', '', '', '', '', '', '', '', '']
referral_url: 
registrar: Gandi SAS (R42-LROR)
status: clientTransferProhibited
updated_date: 2013-08-15 00:20:19
whois_server: 
>>> 

Comments

0

actually, the previus answer now is wrong, urlparse change to urllib.parse, so it will be :

import requests
import urllib.parse
import whois
url = 'http://docs.python.org/3/'
requests.head(url).headers['server']
'Apache/2.2.22 (Debian)'
hostname = urllib.parse.urlparse(url).netloc
print (whois.whois(hostname))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.