How would I go about checking if a domain name is registered? I was thinking about checking if it has a corresponding IP but it doesn't seem to work as well as I had hoped. Is there a solution in either PHP or Python that can check?
-
I just got to know there is a python module named [pywhois](https://bitbucket.org/richardpenman/pywhois). To install it, `pip install python-whois`. – SparkAndShine Jul 21 '15 at 10:01
4 Answers
"Registered" doesn't mean "assigned an IP address". To know whether a domain name is registered, you'll need to do a whois query.
For Python, there's pywhois, but from its web site it seems somewhat immature. Also see this SO question.
For PHP, there's... surprise... phpwhois.
-
Yeah, the whole registered not meaning assigned an ip address is why it failed as a solution for me. – Evan Fosmark Nov 08 '09 at 20:35
Mike Nott has created a simple PHP class that allows you to query the who.is data for any domain you wish.
Once you call
$whois = getwhois($sld, $tld);
you then just need to check the contents of $whois to determine whether the domain is currently registered.
- 40,958
- 16
- 80
- 86
use the net_whois package from pear. for multiple results, which may occur when server names are also reported along with domain names do something similar to:
require_once ¨Net/Whois.php¨;
$whois = new Net_Whois;
$whois->authorative = true;
$data = $whois->query(¨example.com¨);
- 3,804
- 3
- 29
- 31
To check if a domain name is registered you need two informations:
- The whois server for the respective top level domain (or second level domain)
- A matching pattern for the response of that whois server
Those informations do change frequently. This Whois Server list tries to compile the needed informations for more than 500 top level domains. The list also offers an API service to check if a domain is available. The PHP client for that API would be whois-api-php:
$whoisApi = new whoisServerList\WhoisApi("apiKey");
echo $whoisApi->isAvailable("example.net") ? "available" : "registered";
- 7,738
- 2
- 38
- 67