Whois lookup behind proxy using Python
So why use Pois over robust libraries like pythonwhois, pywhois...
-
It supports idn domains.
-
It supports over 1449 tlds (thanks to dnpedia) and if it didn't find any whois server for a specific brand new tld it query
whois.iana.orgto get tld whois server (tlds.jsonfile will be updated when new whois servers fetched). -
It accepts http and socks proxies, thank to
pysocks. -
It accepts user defined whois server to query desired domain.
-
It accepts a timeout for whois operation, some whois servers time out after user quota exceeded.
-
It parses result and if it finds a Registrar whois server, re-whois that server to get complete whois (thick whois).
-
Pois uses
chardetlibrary to detect encoding of whois and give you correctly utf-8 decoded result.
Install dependencies
pip install --user pdm
pdm install
Copy pois folder anywhere you want then import it.
First create a Pois object
p = Pois()You can set a timeout for whois operation by passing timeout argument, timeout must be an integer
to set proxy just pass proxy_info dict with these arguments
proxy_type: must behttp,socks4orsocks5addr: server ip or addressusername: proxy username if specifiedpassword: proxy password if specifiedport: proxy port in integer
to fetch whois of domain just call fetch method, this method take two arguments, domain and whois_server
domainis the domain that you want to fetch whois ofwhois_serveris the whois server that you want to query the domain on that server, if set to None Pois will use the authentic whois server for that domain tld
seetestsfor more examples
from pois import *
# without proxy
try:
p = Pois(timeout=10)
result = p.fetch(domain='github.com', whois_server='whois.verisign-grs.com')
# or
result = p.fetch(domain='github.com',)
except Exception as err:
print(str(err))
# with proxy
try:
proxy_info = {'proxy_type':'http','addr':'localhost', 'port':8118}
p = Pois(timeout=10, proxy_info=proxy_info)
result = p.fetch(domain='github.com', whois_server=None,)
except Exception as err:
print(str(err))
- In many cases, when we query registrar whois server, we get full information but sometimes the registry whois sever gives us full information like 'php.guru', so we return both results
TldsFileError
BadDomainError
NoWhoisServerFoundError
SocketTimeoutError
SocketError
SocketBadProxyError