Added skullY's patches for Network.whois for .orgs.

This commit is contained in:
Jeremy Fincher 2004-02-17 08:08:18 +00:00
parent 6be8850822
commit 976efd87cf
2 changed files with 59 additions and 25 deletions

View File

@ -71,21 +71,55 @@ class Network(callbacks.Privmsg):
except socket.error:
irc.reply('Host not found.')
_tlds = sets.Set(['com', 'net', 'edu'])
_tlds = sets.Set(['com', 'net', 'edu', 'org'])
def whois(self, irc, msg, args):
"""<domain>
Returns WHOIS information on the registration of <domain>. <domain>
must be in tlds .com, .net, or .edu.
must be in tlds .com, .net, .edu, or .org.
"""
domain = privmsgs.getArgs(args)
if '.' not in domain or domain.split('.')[-1] not in self._tlds:
irc.error('<domain> must be in .com, .net, or .edu.')
usertld = domain.split('.')[-1]
if '.' not in domain or usertld not in self._tlds:
irc.error('<domain> must be in .com, .net, .edu, or .org.')
return
elif len(domain.split('.')) != 2:
irc.error('<domain> must be a domain, not a hostname.')
return
t = telnetlib.Telnet('rs.internic.net', 43)
if usertld == 'org':
t = telnetlib.Telnet('whois.pir.org', 43)
t.write(domain)
t.write('\n')
s = t.read_all()
for line in s.splitlines():
line = line.strip()
if not line:
continue
if line.startswith('Sponsoring Registrar'):
registar = ':'.join(line.split(':')[1:])
elif line.startswith('Last Updated On'):
updated = ':'.join(line.split(':')[1:])
elif line.startswith('Created On'):
created = ':'.join(line.split(':')[1:])
elif line.startswith('Expiration Date'):
expires = ':'.join(line.split(':')[1:])
elif line.startswith('Status'):
status = ':'.join(line.split(':')[1:]).lower()
t = telnetlib.Telnet('whois.pir.org', 43)
t.write('registrar id ')
t.write(registar)
t.write('\n')
s = t.read_all()
for line in s.splitlines():
line = line.strip()
if not line:
continue
if line.startswith('Email'):
url = 'registered at '
url += line.split('@')[-1]
else:
t = telnetlib.Telnet('rs.internic.net', 43)
t.write('=')
t.write(domain)
t.write('\n')
s = t.read_all()
@ -93,8 +127,6 @@ class Network(callbacks.Privmsg):
line = line.strip()
if not line:
continue
if line.startswith('Registrar'):
registrar = line.split()[-1].capitalize()
elif line.startswith('Referral'):
url = line.split()[-1]
elif line.startswith('Updated'):

View File

@ -42,7 +42,9 @@ if network:
def testWhois(self):
self.assertNotError('network whois ohio-state.edu')
self.assertError('network whois www.ohio-state.edu')
self.assertError('network whois slashdot.org')
self.assertNotError('network whois kuro5hin.org')
self.assertError('network whois www.kuro5hin.org')
self.assertNotError('network whois microsoft.com')
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: