Giter Site home page Giter Site logo

python-whois's Introduction

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

python-whois's People

Contributors

descent098 avatar gen1us2k avatar ggerasimov avatar gudzikgit avatar k0ste avatar ranzhe avatar tenninjas avatar tierpod avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-whois's Issues

fyi: whoisdomain

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

some bugs about tld_regexpr and datetime

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

wrong data format get ValueError.

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'

NameError: name 'domain' is not defined

Привет, хотел попробовать модуль, но что то не получается
установил - 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
> >>>

ValueError: Unknown date format: '2026-10-11t00:00:00-0700'

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.

info domains not working

$ /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'

.COM expiry date

'expiration_date': r'Expiration Date:\s?(.+)',

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

Python2 and UTC offset (%z)

Errors:

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"

Testcase:

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

Fixed example:

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.

Solicitation

Could you add some more popular TLDs like .pt ?

expiration date extract fail

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

Package in pypi needs to be updated

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

about cache option

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

custom whois servers

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.