Bdzzld
06-26-2007, 01:34 PM
Hi,
Does any one have or know of a PHP script which can query root servers to see if a domain name has been registered and with what DNS servers ?
I'd like to offer this as an alternative to Whois server lookups.
Thanks,
Bdzzld.
epcmedia
06-27-2007, 09:34 AM
I do not think there is an easy way to to do this reliably with core libraries. There is, however, an API service from Enom, and bulk domain registrar. They allow customer to use this service for registration purposes, which I am sure include domain lookup.
http://www.enom.com/resellers/Interfaceinfo.asp
It looks like you might be able to curl() a response from there for lookups.
EPCMEDIA
Jatinder
06-27-2007, 10:28 AM
Use this PHP class:
http://www.phpclasses.org/browse/package/694.html
Bdzzld
06-27-2007, 11:51 AM
Hi Jatinder, actually I'm not looking for a script to query Whois servers. I'm looking for a script to query root servers, which is probably a (Pear?) class around the "dig" command. Via a root server lookup you can determine if a domain name is registered even during downtime of a Whois server. And it's much faster...
mwatkins
06-27-2007, 12:46 PM
I did up such a script once upon a time to help pick new domain names; due to the repeated use of this and volume of names checked, that script has additional local persistent caching features.
Here's a subset of that script, in Python - the NS record lookup component is just a few lines.
I would not query the root servers directly but a local caching nameserver - you can configure your cache as you see fit, but its only polite to reduce the load on the root machines. However, if you are bent on doing that, simply set DNS.default['server'] = ['ip or name root server 1', 'ip or name root server 2', ...].
#!/usr/bin/env python
"""
Simple script to check if a domain is listed in a nameserver.
"""
# install PyDNS: http://pydns.sourceforge.net
# or in FreeBSD /usr/ports/dns/py-dns
import DNS
import sys
DNS.ParseResolvConf()
# you could query the root servers directly but this isn't encouraged, due to
# the needless additional load on root servers and secondly because you'll need
# to map the TLD for the domain to the right root name server. That code is
# not provided herein.
# example of overriding with a single root server:
#DNS.defaults['server'] = ['b.gtld-servers.net']
class Domain:
name = None
exists = False
ns = []
def __init__(self, name):
self.name = name
self.exists, self.ns = get_ns(self.name)
def get_ns(domain):
"""(domain:string) -> (boolean, [string,])
If domain exists returns True and a list of any name servers defined.
"""
query = DNS.Request(domain, qtype="NS").req()
status = query.header['status']
if status == 'NXDOMAIN':
return (False, [])
if status == 'NOERROR':
return (True,
[ns['data'] for ns in query.answers if ns['typename'] == 'NS'])
# something else is wrong
raise SystemError, '%s status returned while querying %s' % (status,
domain)
if __name__ == '__main__':
# example usage
print "Examples --------------"
d = Domain('emc.com')
print d.exists, d.ns
# just using function
exists, nservers = get_ns('apple.com')
print exists, nservers
print "-----------------------"
# reading from a file, one domain per line
if len(sys.argv) == 2: # you supplied a domain file to process
domain_file = sys.argv[1]
domains = [d.strip() for d in open(domain_file) if d.strip()]
answers = [Domain(name) for name in domains]
for a in answers:
# domain, does it exist, what are its name servers
print a.name, a.exists, a.ns
Example script output run against a file with a few valid domains and one invalid name:
% ./check_domains domains.txt
Examples --------------
True ['gw.emc.com', 'ns0.emc.com', 'emcns.emc.com', 'emcns2.emc.com']
True ['nserver.asia.apple.com', 'nserver.euro.apple.com', 'nserver.apple.com', 'nserver2.apple.com', 'nserver3.apple.com', 'nserver4.apple.com']
-----------------------
hp.com True ['eu1.hp.com', 'eu2.hp.com', 'eu3.hp.com', 'am1.hp.com', 'am3.hp.com', 'ap1.hp.com']
ibm.com True ['ns.watson.ibm.com', 'ns.almaden.ibm.com', 'internet-server.zurich.ibm.com', 'ns.austin.ibm.com']
gc.ca True ['rusty.srv.gc.ca', 'jerome.srv.gc.ca', 'ns1.drenet.dnd.ca', 'relay.srv.gc.ca']
foozwjhjhsdjhsd.com False []
Jatinder
06-28-2007, 12:39 AM
I'm looking for a script to query root servers, which is probably a (Pear?) class around the "dig" command. Via a root server lookup you can determine if a domain name is registered even during downtime of a Whois server. And it's much faster...
AFAIK, root name servers have no information about the domains. The root name servers simply contains the entries for the authoritative nameservers for TLDs. Its these authoritative nameservers which have information about domains.
Moreover, root name servers are not supposed to be queried directly.
The PHP class I linked to above uses different nameservers for different TLDs. So there is no single point of failure.