gen1us2k / python-whois Goto Github PK
View Code? Open in Web Editor NEWFork of https://code.google.com/p/python-whois/ project
Fork of https://code.google.com/p/python-whois/ project
WHOIS ============= Python module/library for retrieving WHOIS information of domains. By DDarko http://ddarko.org/ Features ============= * Python wrapper for Linux "whois" command * simple interface to access parsed WHOIS data for a given domain * able to extract data for all the popular TLDs (com, net, org, uk, pl, ru, рф, lv, jp, co_jp, de, at, eu, biz, info, online, center, support, name, us, co, me, be, nz, cz, it, fr, kg, vc, fm, tv, edu, ca, pw, bid, host, party, pro, review, site, space, top, website, win) * query a WHOIS server directly instead of going through an intermediate web service like many others do * works with Python 2.4+ and Python 3.x * all dates as datetime objects * possibility to cache results Usage example ============= >>> import whois >>> domain = whois.query('google.com') >>> print(domain.__dict__) { 'expiration_date': datetime.datetime(2020, 9, 14, 0, 0), 'last_updated': datetime.datetime(2011, 7, 20, 0, 0), 'registrar': 'MARKMONITOR INC.', 'name': 'google.com', 'creation_date': datetime.datetime(1997, 9, 15, 0, 0) } >>> print(domain.name) google.com >>> print(domain.expiration_date) 2020-09-14 00:00:00
you have successfully made this Linux only.
i noted this repo only recently,
i am a co maintainer of https://github.com/DannyCork/python-whois, where the owner seems to have stagnated on publishing new releases.
i started a new repo at: https://github.com/mboot-github/WhoisDomain,
with a pypi lib at https://pypi.org/project/whoisdomain/
i will add all your tld's to that and your test programs to my whoisdomain and the DannyCork/python-whois
perhaps in the future the efforts can be combined as they all derive from the original google code project
When I add the newgtld .global it will consider syntax error
global = {'extend': 'tv',}
global seems to be the keyword
and datatime formate for some tlds are illegal
google.help and also google.link
ValueError: Unknown date format: '2015-01-21t20:27:25.060z
who=whois.query('rechtsanwalt-baumann.de')
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python3.7/site-packages/whois/init.py", line 42, in query
return Domain(pd) if pd['domain_name'][0] else None
File "/usr/local/lib/python3.7/site-packages/whois/_3_adjust.py", line 17, in init
self.last_updated = str_to_date(data['updated_date'][0])
File "/usr/local/lib/python3.7/site-packages/whois/_3_adjust.py", line 95, in str_to_date
raise ValueError("Unknown date format: '{0}'".format(s))
ValueError: Unknown date format: '2018-01'
Привет, хотел попробовать модуль, но что то не получается
установил - python-whois-extended 0.6.10
> root@zabbix:/home/appliance# python3
> Python 3.5.2 (default, Nov 23 2017, 16:37:01)
> [GCC 5.4.0 20160609] on linux
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import whois
> >>> domain = whois.query('google.com')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/local/lib/python3.5/dist-packages/whois/__init__.py", line 52, in query
> pd = do_parse(do_query(d, force, cache_file, slow_down, ignore_returncode), tld)
> File "/usr/local/lib/python3.5/dist-packages/whois/_1_query.py", line 40, in do_query
> _do_whois_query(dl, ignore_returncode),
> File "/usr/local/lib/python3.5/dist-packages/whois/_1_query.py", line 60, in _do_whois_query
> if not ignore_returncode and p.returncode != 0: raise Exception(r)
> Exception: Domain Name: GOOGLE.COM
> Registry Domain ID: 2138514_DOMAIN_COM-VRSN
> Registrar WHOIS Server: whois.markmonitor.com
> Registrar URL: http://www.markmonitor.com
> Updated Date: 2018-02-21T18:36:40Z
> Creation Date: 1997-09-15T04:00:00Z
> Registry Expiry Date: 2020-09-14T04:00:00Z
> Registrar: MarkMonitor Inc.
> Registrar IANA ID: 292
> Registrar Abuse Contact Email: [email protected]
> Registrar Abuse Contact Phone: +1.2083895740
> Domain Status: clientDeleteProhibited https://icann.org/epp#clientDeleteProhibited
> Domain Status: clientTransferProhibited https://icann.org/epp#clientTransferProhibited
> Domain Status: clientUpdateProhibited https://icann.org/epp#clientUpdateProhibited
> Domain Status: serverDeleteProhibited https://icann.org/epp#serverDeleteProhibited
> Domain Status: serverTransferProhibited https://icann.org/epp#serverTransferProhibited
> Domain Status: serverUpdateProhibited https://icann.org/epp#serverUpdateProhibited
> Name Server: NS1.GOOGLE.COM
> Name Server: NS2.GOOGLE.COM
> Name Server: NS3.GOOGLE.COM
> Name Server: NS4.GOOGLE.COM
> DNSSEC: unsigned
> URL of the ICANN Whois Inaccuracy Complaint Form: https://www.icann.org/wicf/
> >>> Last update of whois database: 2018-04-24T04:45:29Z <<<
>
> For more information on Whois status codes, please visit https://icann.org/epp
>
> NOTICE: The expiration date displayed in this record is the date the
> registrar's sponsorship of the domain name registration in the registry is
> currently set to expire. This date does not necessarily reflect the expiration
> date of the domain name registrant's agreement with the sponsoring
> registrar. Users may consult the sponsoring registrar's Whois database to
> view the registrar's reported date of expiration for this registration.
>
> TERMS OF USE: You are not authorized to access or query our Whois
> database through the use of electronic processes that are high-volume and
> automated except as reasonably necessary to register domain names or
> modify existing registrations; the Data in VeriSign Global Registry
> Services' ("VeriSign") Whois database is provided by VeriSign for
> information purposes only, and to assist persons in obtaining information
> about or related to a domain name registration record. VeriSign does not
> guarantee its accuracy. By submitting a Whois query, you agree to abide
> by the following terms of use: You agree that you may use this Data only
> for lawful purposes and that under no circumstances will you use this Data
> to: (1) allow, enable, or otherwise support the transmission of mass
> unsolicited, commercial advertising or solicitations via e-mail, telephone,
> or facsimile; or (2) enable high volume, automated, electronic processes
> that apply to VeriSign (or its computer systems). The compilation,
> repackaging, dissemination or other use of this Data is expressly
> prohibited without the prior written consent of VeriSign. You agree not to
> use electronic processes that are automated and high-volume to access or
> query the Whois database except as reasonably necessary to register
> domain names or modify existing registrations. VeriSign reserves the right
> to restrict your access to the Whois database in its sole discretion to ensure
> operational stability. VeriSign may restrict or terminate your access to the
> Whois database for failure to abide by these terms of use. VeriSign
> reserves the right to modify these terms at any time.
>
> The Registry database contains ONLY .COM, .NET, .EDU domains and
> Registrars.
>
> >>> print(domain.__dict__)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> NameError: name 'domain' is not defined
> >>>
Hi, I used this python module on my windows 10, and download whois binary file into PATH, then I try play with this module, but I got this error.
File "C:\Python27\lib\site-packages\whois\_3_adjust.py", line 103, in str_to_date_py2
raise ValueError("Unknown date format: '%s'" % s)
ValueError: Unknown date format: '2026-10-11t00:00:00-0700'
I think maybe some time format lose in 'whois_3_adjust.py' file. I try fix this issue, but it failed at last.
# http://docs.python.org/library/datetime.html#strftime-strptime-behavior
DATE_FORMATS = [
A mistake regex expression can cause this problem as well, I guess.
def str_to_date_py2(s):
tmp = re.findall('\+([0-9]{2})00', s)
if tmp:
tz = int(tmp[0])
Best regards.
$ /usr/lib/nagios/plugins/check_domain -d lyalyuev.info
Traceback (most recent call last):
File "/usr/lib/nagios/plugins/check_domain", line 27, in
check_domain(options.domain)
File "/usr/lib/nagios/plugins/check_domain", line 14, in check_domain
if (q.expiration_date - datetime.now()).days <= 30:
TypeError: unsupported operand type(s) for -: 'NoneType' and 'datetime.datetime'
python-whois/whois/tld_regexpr.py
Line 10 in 21693a4
Hello,
Some ".com" registrar (Gandi SAS at least) do not only give the expiration date as "Expiration Date", but "Registry Expiry Date".
So I propose to change the regex from
'expiration_date': r'Expiration Date:\s?(.+)' to
'expiration_date': r'Expir.* Date:\s?(.+Z)' (well, Z is not obvious to be necessary)
Regards
Test google.jp with python2
google.jp
Traceback (most recent call last):
File "test.py", line 14, in <module>
w = whois.query(d, ignore_returncode=1)
File "/tmp/google.jp/whois/__init__.py", line 63, in query
return Domain(pd) if pd['domain_name'][0] else None
File "/tmp/google.jp/whois/_3_adjust.py", line 18, in __init__
self.last_updated = str_to_date(data['updated_date'][0])
File "/tmp/google.jp/whois/_3_adjust.py", line 82, in str_to_date
if PYTHON_VERSION < 3: return str_to_date_py2(s)
File "/tmp/google.jp/whois/_3_adjust.py", line 106, in str_to_date_py2
raise ValueError("Unknown date format: '%s'" % s)
ValueError: Unknown date format: '2015/06/01 01:05:07 (+0900)'
Test google.jp with python3
google.jp
expiration_date "2016-05-31 00:00:00"
name "google.jp"
registrant_cc ""
registrar ""
name_servers "{'ns2.google.com', 'ns3.google.com', 'ns4.google.com', 'ns1.google.com'}"
creation_date "2005-05-30 00:00:00"
last_updated "2015-06-01 01:05:07+09:00"
import datetime
def func(data, sample):
try:
return datetime.datetime.strptime(data, sample)
except:
raise ValueError("Unknown date format: '%s'" % data)
sample = '%Y/%m/%d %H:%M:%S (%z)'
data = '2015/06/01 01:05:07 (+0900)'
print(func(data, sample))
Returns with python2:
Traceback (most recent call last):
File "example.py", line 12, in <module>
print(func(data, sample))
File "example.py", line 7, in func
raise ValueError("Unknown date format: '%s'" % data)
ValueError: Unknown date format: '2015/06/01 01:05:07 (+0900)'
Returns with python3:
2015-06-01 01:05:07+09:00
import datetime, sys, re
def func(data, sample):
if PYTHON_VERSION < 3:
tmp = re.findall('\+([0-9]{2})00', data)
if tmp:
tz = int(tmp[0])
else:
tz = 0
data = re.sub('\s\((\+)([0-9]{2})([0-9]{2})\)', '', data)
sample = re.sub('\s\(\%z\)', '', sample)
try:
return datetime.datetime.strptime(data, sample) + datetime.timedelta(hours=tz)
except:
raise ValueError("[PYTHON2] Unknown date format: '%s'" % data)
try:
return datetime.datetime.strptime(data, sample)
except:
raise ValueError("[PYTHON3] Unknown date format: '%s'" % data)
PYTHON_VERSION = sys.version_info[0]
sample = '%Y/%m/%d %H:%M:%S (%z)'
data = '2015/06/01 01:05:07 (+0900)'
print(func(data, sample))
Returns with python2:
2015-06-01 10:05:07
Returns with python3:
2015-06-01 01:05:07+09:00
Seems %z is not work with python2. But in documentation is present. In code implement workaround for python2 but not fully. Or just not works on last versions of python2, don't know.
If results of second example is correct, I can prepare a patch.
Could you add some more popular TLDs like .pt ?
I am now using the latest python version Python 3.7.1 in centos 7
and I can't extract expiration date from the whois
import whois
domain = whois.query('google.com')
print(domain.dict)
{'name': 'google.com', 'registrar': 'MarkMonitor Inc.', 'registrant_cc': '', 'creation_date': datetime.datetime(1997, 9, 15, 4, 0), 'expiration_date': None, 'last_updated': datetime.datetime(2018, 2, 21, 18, 36, 40), 'name_servers': {'ns4.google.com', 'ns1.google.com', 'ns3.google.com', 'ns2.google.com'}}
you see 'expiration_date': None
Can't replicate whois command in python version?
or include it in the source?
When i clone the repo and run the tests, all supported TLD work fine
when i do pip3 install python-extended-whois and run the tests, i get errors about unsupported TLDs, so this prrobably means the package needs updating on pypi
Hello
I can see there is a cache parm available for query, I am new for python study and I can't figure out how the cache works in the gist codes, could you please provide me with a demo code for cache usage in this script
thank you
Hello
Since this script is based on linux whois command, some of the tlds are not supported or not works well , such as
.fun , .art .bar .ooo etc, it will throws errors
nic.fun connect: Network is unreachable
so is it possible to custom the whois servers for those tlds ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.