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

View File

@ -42,7 +42,9 @@ if network:
def testWhois(self): def testWhois(self):
self.assertNotError('network whois ohio-state.edu') self.assertNotError('network whois ohio-state.edu')
self.assertError('network whois www.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: # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: