whois/parser.py
changeset 53 e2eaf1755fce
parent 50 9b1df2267f84
child 56 ff15b368adaf
equal deleted inserted replaced
51:1459aa5d7ce4 53:e2eaf1755fce
   188             return WhoisBe(domain, text)
   188             return WhoisBe(domain, text)
   189         elif domain.endswith('.рф'):
   189         elif domain.endswith('.рф'):
   190             return WhoisRf(domain, text)
   190             return WhoisRf(domain, text)
   191         elif domain.endswith('.info'):
   191         elif domain.endswith('.info'):
   192             return WhoisInfo(domain, text)
   192             return WhoisInfo(domain, text)
       
   193         elif domain.endswith('.su'):
       
   194             return WhoisSu(domain, text)
       
   195         elif domain.endswith('.kg'):
       
   196             return WhoisKg(domain, text)
       
   197         elif domain.endswith('.io'):
       
   198             return WhoisIo(domain, text)
       
   199         elif domain.endswith('.biz'):
       
   200             return WhoisBiz(domain, text)
       
   201         elif domain.endswith('.mobi'):
       
   202             return WhoisMobi(domain, text)
   193         else:
   203         else:
   194             return WhoisEntry(domain, text)
   204             return WhoisEntry(domain, text)
   195 
   205 
   196 
   206 
   197 class WhoisCom(WhoisEntry):
   207 class WhoisCom(WhoisEntry):
   716             raise PywhoisError(text)
   726             raise PywhoisError(text)
   717         else:
   727         else:
   718             WhoisEntry.__init__(self, domain, text, self.regex)
   728             WhoisEntry.__init__(self, domain, text, self.regex)
   719 
   729 
   720 
   730 
   721 class WhoisRf(WhoisEntry):
   731 class WhoisRf(WhoisRu):
   722     """Whois parser for .rf domains"""
   732 
   723 
   733     """Whois parser for .rf domains
   724     regex = {
   734     """
   725         'expiration_date': 'free-date:\s*(.+)',
   735     def __init__(self):
   726     }
   736         super(WhoisRf, self).__init__()
   727 
       
   728     def __init__(self, domain, text):
       
   729         if text.strip() == 'No entries found':
       
   730             raise PywhoisError(text)
       
   731         else:
       
   732             WhoisEntry.__init__(self, domain, text, self.regex)
       
   733 
   737 
   734 
   738 
   735 class WhoisDe(WhoisEntry):
   739 class WhoisDe(WhoisEntry):
   736     """Whois parser for .de domains"""
   740     """Whois parser for .de domains"""
   737 
   741 
   798     def __init__(self, domain, text):
   802     def __init__(self, domain, text):
   799         if text.strip() == 'NOT FOUND':
   803         if text.strip() == 'NOT FOUND':
   800             raise PywhoisError(text)
   804             raise PywhoisError(text)
   801         else:
   805         else:
   802             WhoisEntry.__init__(self, domain, text, self.regex)
   806             WhoisEntry.__init__(self, domain, text, self.regex)
       
   807 
       
   808 
       
   809 
       
   810 class WhoisSu(WhoisRu):
       
   811 
       
   812     """Whois parser for .su domains
       
   813     """
       
   814     def __init__(self):
       
   815         super(WhoisSu, self).__init__()
       
   816 
       
   817 
       
   818 class WhoisClub(WhoisEntry):
       
   819 
       
   820     """Whois parser for .us domains
       
   821     """
       
   822     regex = {
       
   823         'domain_name':                    'Domain Name:\s*(.+)',
       
   824         'domain__id':                     'Domain ID:\s*(.+)',
       
   825         'registrar':                      'Sponsoring Registrar:\s*(.+)',
       
   826         'registrar_id':                   'Sponsoring Registrar IANA ID:\s*(.+)',
       
   827         'registrar_url':                  'Registrar URL \(registration services\):\s*(.+)',
       
   828         # list of statuses
       
   829         'status':                         'Domain Status:\s*(.+)',
       
   830         'registrant_id':                  'Registrant ID:\s*(.+)',
       
   831         'registrant_name':                'Registrant Name:\s*(.+)',
       
   832         'registrant_address1':            'Registrant Address1:\s*(.+)',
       
   833         'registrant_address2':            'Registrant Address2:\s*(.+)',
       
   834         'registrant_city':                'Registrant City:\s*(.+)',
       
   835         'registrant_state_province':      'Registrant State/Province:\s*(.+)',
       
   836         'registrant_postal_code':         'Registrant Postal Code:\s*(.+)',
       
   837         'registrant_country':             'Registrant Country:\s*(.+)',
       
   838         'registrant_country_code':        'Registrant Country Code:\s*(.+)',
       
   839         'registrant_phone_number':        'Registrant Phone Number:\s*(.+)',
       
   840         'registrant_email':               'Registrant Email:\s*(.+)',
       
   841         'registrant_application_purpose': 'Registrant Application Purpose:\s*(.+)',
       
   842         'registrant_nexus_category':      'Registrant Nexus Category:\s*(.+)',
       
   843         'admin_id':                       'Administrative Contact ID:\s*(.+)',
       
   844         'admin_name':                     'Administrative Contact Name:\s*(.+)',
       
   845         'admin_address1':                 'Administrative Contact Address1:\s*(.+)',
       
   846         'admin_address2':                 'Administrative Contact Address2:\s*(.+)',
       
   847         'admin_city':                     'Administrative Contact City:\s*(.+)',
       
   848         'admin_state_province':           'Administrative Contact State/Province:\s*(.+)',
       
   849         'admin_postal_code':              'Administrative Contact Postal Code:\s*(.+)',
       
   850         'admin_country':                  'Administrative Contact Country:\s*(.+)',
       
   851         'admin_country_code':             'Administrative Contact Country Code:\s*(.+)',
       
   852         'admin_phone_number':             'Administrative Contact Phone Number:\s*(.+)',
       
   853         'admin_email':                    'Administrative Contact Email:\s*(.+)',
       
   854         'admin_application_purpose':      'Administrative Application Purpose:\s*(.+)',
       
   855         'admin_nexus_category':           'Administrative Nexus Category:\s*(.+)',
       
   856         'billing_id':                     'Billing Contact ID:\s*(.+)',
       
   857         'billing_name':                   'Billing Contact Name:\s*(.+)',
       
   858         'billing_address1':               'Billing Contact Address1:\s*(.+)',
       
   859         'billing_address2':               'Billing Contact Address2:\s*(.+)',
       
   860         'billing_city':                   'Billing Contact City:\s*(.+)',
       
   861         'billing_state_province':         'Billing Contact State/Province:\s*(.+)',
       
   862         'billing_postal_code':            'Billing Contact Postal Code:\s*(.+)',
       
   863         'billing_country':                'Billing Contact Country:\s*(.+)',
       
   864         'billing_country_code':           'Billing Contact Country Code:\s*(.+)',
       
   865         'billing_phone_number':           'Billing Contact Phone Number:\s*(.+)',
       
   866         'billing_email':                  'Billing Contact Email:\s*(.+)',
       
   867         'billing_application_purpose':    'Billing Application Purpose:\s*(.+)',
       
   868         'billing_nexus_category':         'Billing Nexus Category:\s*(.+)',
       
   869         'tech_id':                        'Technical Contact ID:\s*(.+)',
       
   870         'tech_name':                      'Technical Contact Name:\s*(.+)',
       
   871         'tech_address1':                  'Technical Contact Address1:\s*(.+)',
       
   872         'tech_address2':                  'Technical Contact Address2:\s*(.+)',
       
   873         'tech_city':                      'Technical Contact City:\s*(.+)',
       
   874         'tech_state_province':            'Technical Contact State/Province:\s*(.+)',
       
   875         'tech_postal_code':               'Technical Contact Postal Code:\s*(.+)',
       
   876         'tech_country':                   'Technical Contact Country:\s*(.+)',
       
   877         'tech_country_code':              'Technical Contact Country Code:\s*(.+)',
       
   878         'tech_phone_number':              'Technical Contact Phone Number:\s*(.+)',
       
   879         'tech_email':                     'Technical Contact Email:\s*(.+)',
       
   880         'tech_application_purpose':       'Technical Application Purpose:\s*(.+)',
       
   881         'tech_nexus_category':            'Technical Nexus Category:\s*(.+)',
       
   882         # list of name servers
       
   883         'name_servers':                   'Name Server:\s*(.+)',
       
   884         'created_by_registrar':           'Created by Registrar:\s*(.+)',
       
   885         'last_updated_by_registrar':      'Last Updated by Registrar:\s*(.+)',
       
   886         'creation_date':                  'Domain Registration Date:\s*(.+)',
       
   887         'expiration_date':                'Domain Expiration Date:\s*(.+)',
       
   888         'updated_date':                   'Domain Last Updated Date:\s*(.+)',
       
   889     }
       
   890 
       
   891     def __init__(self, domain, text):
       
   892         if 'Not found:' in text:
       
   893             raise PywhoisError(text)
       
   894         else:
       
   895             WhoisEntry.__init__(self, domain, text, self.regex)
       
   896 
       
   897 
       
   898 class WhoisIo(WhoisEntry):
       
   899 
       
   900     """Whois parser for .io domains"""
       
   901     regex = {
       
   902         'status':           'Status\s*:\s*(.+)',
       
   903         'name_servers':     'NS \d?\s*:\s*(.+)',
       
   904         'owner':            'Owner\s*:\s*(.+)',
       
   905         'expiration_date':  'Expiry\s*:\s*(.+)',
       
   906         'domain_name':      'Domain\s*:\s*(.+)',
       
   907         'registrar':        r'Check for \'[\w\.]*\' --- (.+)',
       
   908     }
       
   909 
       
   910     def __init__(self, domain, text):
       
   911         if 'is available for purchase' in text:
       
   912             raise PywhoisError(text)
       
   913         else:
       
   914             WhoisEntry.__init__(self, domain, text, self.regex)
       
   915 
       
   916 
       
   917 class WhoisBiz(WhoisEntry):
       
   918 
       
   919     """Whois parser for .biz domains"""
       
   920 
       
   921     def __init__(self, domain, text):
       
   922         super(WhoisUs, self).__init__(domain, text)
       
   923 
       
   924 
       
   925 class WhoisMobi(WhoisMe):
       
   926 
       
   927     def __init__(self, domain, text):
       
   928         super(WhoisMobi, self).__init__(domain, text)
       
   929 
       
   930 
       
   931 class WhoisKg(WhoisEntry):
       
   932     regex = {
       
   933         'domain_name':                    'Domain\s*([\w]+\.[\w]{2,5})',
       
   934         'registrar':                      'Domain support: \s*(.+)',
       
   935         'registrant_name':                'Name:\s*(.+)',
       
   936         'registrant_address1':            'Address:\s*(.+)',
       
   937         'registrant_phone_number':        'phone:\s*(.+)',
       
   938         'registrant_email':               'Email:\s*(.+)',
       
   939         # # list of name servers
       
   940         'name_servers':                   'Name servers in the listed order:\s*([\d\w\.\s]+)',
       
   941         # 'name_servers':      r'([\w]+\.[\w]+\.[\w]{2,5}\s*\d{1,3}\.\d]{1,3}\.[\d]{1-3}\.[\d]{1-3})',
       
   942         'creation_date':                  'Record created:\s*(.+)',
       
   943         'expiration_date':                'Record expires on \s*(.+)',
       
   944         'updated_date':                   'Record last updated on\s*(.+)',
       
   945 
       
   946     }
       
   947     def __init__(self, domain, text):
       
   948         if 'Data not found. This domain is available for registration' in text:
       
   949             raise PywhoisError(text)
       
   950         else:
       
   951             WhoisEntry.__init__(self, domain, text, self.regex)
       
   952 
       
   953 
       
   954