From 31c8af3fda1284118eec427a9e4e95f7a8002f4b Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 24 Feb 2004 21:52:53 +0000 Subject: [PATCH] Yay! Now Network.whois can retrieve information for any domain. --- ChangeLog | 10 ++++ plugins/Network.py | 117 ++++++++++++++++++++++--------------------- test/test_Network.py | 3 +- 3 files changed, 73 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index 629e1b33f..d85bce269 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ + * Updated Network.whois so that it can now retrieve + information on all domains. + + * Updated the Weather plugin to be retrieve weather from + either hamweather.net or cnn.com. Also added + supybot.plugins.Weather.{weatherCommand,temperatureUnit} so + that you can specify which command (Weather.cnn or + Weather.ham) to use when Weather.weather is called and in which + unit (C, F, K) to report the weather. + * Made standard replies (such as supybot.replies.success, etc.) use the standard substitute (such as $nick, $who, $channel, etc.) in their text. diff --git a/plugins/Network.py b/plugins/Network.py index 8b08ec1aa..5bfd75e5f 100644 --- a/plugins/Network.py +++ b/plugins/Network.py @@ -71,75 +71,80 @@ class Network(callbacks.Privmsg): except socket.error: irc.reply('Host not found.') - _tlds = sets.Set(['com', 'net', 'edu', 'org']) + _tlds = sets.Set(['com', 'net', 'edu']) + _registrar = ['Sponsoring Registrar', 'Registrar', 'source'] + _updated = ['Last Updated On', 'Domain Last Updated Date', 'Updated Date', + 'Last Modified', 'changed'] + _created = ['Created On', 'Domain Registration Date', 'Creation Date'] + _expires = ['Expiration Date', 'Domain Expiration Date'] + _status = ['Status', 'Domain Status', 'status'] def whois(self, irc, msg, args): """ - Returns WHOIS information on the registration of . - must be in tlds .com, .net, .edu, or .org. + Returns WHOIS information on the registration of . """ domain = privmsgs.getArgs(args) usertld = domain.split('.')[-1] - if '.' not in domain or usertld not in self._tlds: + if '.' not in domain: irc.error(' must be in .com, .net, .edu, or .org.') return elif len(domain.split('.')) != 2: irc.error(' must be a domain, not a hostname.') return - 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] + if usertld in self._tlds: + server = 'rs.internic.net' + search = '=%s' % domain 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() + server = '%s.whois-servers.net' % usertld + search = domain try: - s = '%s <%s> is %s; registered %s, updated %s, expires %s.' % \ - (domain, url, status, created, updated, expires) + t = telnetlib.Telnet(server, 43) + except socket.error, e: + irc.error(str(e)) + return + t.write(search) + t.write('\n') + s = t.read_all() + (registrar, updated, created, expires, status) = ('', '', '', '', '') + for line in s.splitlines(): + line = line.strip() + if not line or ':' not in line: + continue + if not registrar and any(line.startswith, self._registrar): + registrar = ':'.join(line.split(':')[1:]).strip() + elif not updated and any(line.startswith, self._updated): + s = ':'.join(line.split(':')[1:]).strip() + updated = 'updated %s' % s + elif not created and any(line.startswith, self._created): + s = ':'.join(line.split(':')[1:]).strip() + created = 'registered %s' % s + elif not expires and any(line.startswith, self._expires): + s = ':'.join(line.split(':')[1:]).strip() + expires = 'expires %s' % s + elif not status and any(line.startswith, self._status): + status = ':'.join(line.split(':')[1:]).strip().lower() + if not status: + status = 'unknown' + try: + t = telnetlib.Telnet('whois.pir.org', 43) + except socket.error, e: + irc.error(str(e)) + return + t.write('registrar id ') + t.write(registrar) + t.write('\n') + s = t.read_all() + for line in s.splitlines(): + line = line.strip() + if not line: + continue + if line.startswith('Email'): + url = ' ' % line.split('@')[-1] + if line == 'Not a valid ID pattern': + url = '' + try: + s = '%s%s is %s; %s.' % (domain, url, status, + ', '.join(filter(None, [created, updated, expires]))) irc.reply(s) except NameError, e: irc.error('I couldn\'t find such a domain.') diff --git a/test/test_Network.py b/test/test_Network.py index 17b47feb4..ea4cf0e47 100644 --- a/test/test_Network.py +++ b/test/test_Network.py @@ -32,7 +32,7 @@ from testsupport import * if network: - class NetworkTestCase(PluginTestCase, PluginDocumentation): + class NetworkTestCase(PluginTestCase): plugins = ['Network'] def testDns(self): self.assertNotError('dns slashdot.org') @@ -45,6 +45,7 @@ if network: self.assertNotError('network whois kuro5hin.org') self.assertError('network whois www.kuro5hin.org') self.assertNotError('network whois microsoft.com') + self.assertNotError('network whois goatse.cx') # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: