Improve our whois handling. whois.pir.org became a bit more strict on the

input they accept.
This commit is contained in:
James Vega 2004-09-25 17:29:27 +00:00
parent 19c4948d97
commit 334c5f9456

View File

@ -70,6 +70,7 @@ class Internet(callbacks.Privmsg):
irc.reply('Host not found.') irc.reply('Host not found.')
_tlds = sets.Set(['com', 'net', 'edu']) _tlds = sets.Set(['com', 'net', 'edu'])
_domain = ['Domain Name', 'Server Name']
_registrar = ['Sponsoring Registrar', 'Registrar', 'source'] _registrar = ['Sponsoring Registrar', 'Registrar', 'source']
_updated = ['Last Updated On', 'Domain Last Updated Date', 'Updated Date', _updated = ['Last Updated On', 'Domain Last Updated Date', 'Updated Date',
'Last Modified', 'changed'] 'Last Modified', 'changed']
@ -81,7 +82,7 @@ class Internet(callbacks.Privmsg):
Returns WHOIS information on the registration of <domain>. Returns WHOIS information on the registration of <domain>.
""" """
domain = privmsgs.getArgs(args) domain = privmsgs.getArgs(args).lower()
usertld = domain.split('.')[-1] usertld = domain.split('.')[-1]
if '.' not in domain: if '.' not in domain:
irc.error('<domain> must be in .com, .net, .edu, or .org.') irc.error('<domain> must be in .com, .net, .edu, or .org.')
@ -103,11 +104,21 @@ class Internet(callbacks.Privmsg):
t.write(search) t.write(search)
t.write('\n') t.write('\n')
s = t.read_all() s = t.read_all()
(registrar, updated, created, expires, status) = ('', '', '', '', '') server = registrar = updated = created = expires = status = ''
for line in s.splitlines(): for line in s.splitlines():
line = line.strip() line = line.strip()
if not line or ':' not in line: if not line or ':' not in line:
continue continue
if not server and any(line.startswith, self._domain):
server = ':'.join(line.split(':')[1:]).strip().lower()
# Let's add this check so that we don't respond with info for
# a different domain. E.g., doing a whois for microsoft.com
# and replying with the info for microsoft.com.wanadoodoo.com
if server != domain:
server = ''
continue
if not server:
continue
if not registrar and any(line.startswith, self._registrar): if not registrar and any(line.startswith, self._registrar):
registrar = ':'.join(line.split(':')[1:]).strip() registrar = ':'.join(line.split(':')[1:]).strip()
elif not updated and any(line.startswith, self._updated): elif not updated and any(line.startswith, self._updated):
@ -128,23 +139,26 @@ class Internet(callbacks.Privmsg):
except socket.error, e: except socket.error, e:
irc.error(str(e)) irc.error(str(e))
return return
t.write('registrar id ') t.write('registrar ')
t.write(registrar) t.write(registrar.split('(')[0].strip())
t.write('\n') t.write('\n')
s = t.read_all() s = t.read_all()
url = ''
for line in s.splitlines(): for line in s.splitlines():
line = line.strip() line = line.strip()
if not line: if not line:
continue continue
if line.startswith('Email'): if line.startswith('Email'):
url = ' <registered at %s>' % line.split('@')[-1] url = ' <registered at %s>' % line.split('@')[-1]
if line == 'Not a valid ID pattern': elif line.startswith('Registrar Organization:'):
url = ' <registered by %s>' % line.split(':')[1].strip()
elif line == 'Not a valid ID pattern':
url = '' url = ''
try: if server and status:
s = '%s%s is %s; %s.' % (domain, url, status, info = filter(None, [status, created, updated, expires])
', '.join(filter(None, [created, updated, expires]))) s = '%s%s is %s.' % (server, url, utils.commaAndify(info))
irc.reply(s) irc.reply(s)
except NameError, e: else:
irc.error('I couldn\'t find such a domain.') irc.error('I couldn\'t find such a domain.')