mirror of
https://github.com/progval/Limnoria.git
synced 2025-05-05 09:50:52 -05:00
Internet: Add support for TLDs and IP addresses in @whois. Closes GH-1253.
This commit is contained in:
parent
d416c3384e
commit
b4182753be
@ -72,10 +72,13 @@ class Internet(callbacks.Plugin):
|
|||||||
dns = wrap(dns, ['something'])
|
dns = wrap(dns, ['something'])
|
||||||
|
|
||||||
_domain = ['Domain Name', 'Server Name', 'domain']
|
_domain = ['Domain Name', 'Server Name', 'domain']
|
||||||
|
_netrange = ['NetRange', 'inetnum']
|
||||||
_registrar = ['Sponsoring Registrar', 'Registrar', 'source']
|
_registrar = ['Sponsoring Registrar', 'Registrar', 'source']
|
||||||
|
_netname = ['NetName', 'inetname']
|
||||||
_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', 'last-modified']
|
||||||
_created = ['Created On', 'Domain Registration Date', 'Creation Date']
|
_created = ['Created On', 'Domain Registration Date', 'Creation Date',
|
||||||
|
'created', 'RegDate']
|
||||||
_expires = ['Expiration Date', 'Domain Expiration Date']
|
_expires = ['Expiration Date', 'Domain Expiration Date']
|
||||||
_status = ['Status', 'Domain Status', 'status']
|
_status = ['Status', 'Domain Status', 'status']
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
@ -84,22 +87,29 @@ class Internet(callbacks.Plugin):
|
|||||||
|
|
||||||
Returns WHOIS information on the registration of <domain>.
|
Returns WHOIS information on the registration of <domain>.
|
||||||
"""
|
"""
|
||||||
usertld = domain.split('.')[-1]
|
if utils.net.isIP(domain):
|
||||||
if '.' not in domain:
|
whois_server = 'whois.arin.net'
|
||||||
irc.errorInvalid(_('domain'))
|
usertld = 'ipaddress'
|
||||||
return
|
elif '.' in domain:
|
||||||
|
usertld = domain.split('.')[-1]
|
||||||
|
whois_server = '%s.whois-servers.net' % usertld
|
||||||
|
else:
|
||||||
|
usertld = None
|
||||||
|
whois_server = 'whois.iana.org'
|
||||||
try:
|
try:
|
||||||
sock = utils.net.getSocket('%s.whois-servers.net' % usertld,
|
sock = utils.net.getSocket(whois_server,
|
||||||
vhost=conf.supybot.protocols.irc.vhost(),
|
vhost=conf.supybot.protocols.irc.vhost(),
|
||||||
vhostv6=conf.supybot.protocols.irc.vhostv6(),
|
vhostv6=conf.supybot.protocols.irc.vhostv6(),
|
||||||
)
|
)
|
||||||
sock.connect(('%s.whois-servers.net' % usertld, 43))
|
sock.connect((whois_server, 43))
|
||||||
except socket.error as e:
|
except socket.error as e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
return
|
return
|
||||||
sock.settimeout(5)
|
sock.settimeout(5)
|
||||||
if usertld == 'com':
|
if usertld == 'com':
|
||||||
sock.send(b'=')
|
sock.send(b'=')
|
||||||
|
elif usertld == 'ipaddress':
|
||||||
|
sock.send(b'n + ')
|
||||||
sock.send(domain.encode('ascii'))
|
sock.send(domain.encode('ascii'))
|
||||||
sock.send(b'\r\n')
|
sock.send(b'\r\n')
|
||||||
|
|
||||||
@ -107,12 +117,17 @@ class Internet(callbacks.Plugin):
|
|||||||
end_time = time.time() + 5
|
end_time = time.time() + 5
|
||||||
try:
|
try:
|
||||||
while end_time>time.time():
|
while end_time>time.time():
|
||||||
|
time.sleep(0.1)
|
||||||
s += sock.recv(4096)
|
s += sock.recv(4096)
|
||||||
except socket.error:
|
except socket.error:
|
||||||
pass
|
pass
|
||||||
server = registrar = updated = created = expires = status = ''
|
sock.close()
|
||||||
|
print(s)
|
||||||
|
server = netrange = netname = registrar = updated = created = expires = status = ''
|
||||||
for line in s.splitlines():
|
for line in s.splitlines():
|
||||||
line = line.decode('utf8').strip()
|
line = line.decode('utf8').strip()
|
||||||
|
print(line)
|
||||||
|
print(self._netrange)
|
||||||
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):
|
if not server and any(line.startswith, self._domain):
|
||||||
@ -123,10 +138,14 @@ class Internet(callbacks.Plugin):
|
|||||||
if server != domain:
|
if server != domain:
|
||||||
server = ''
|
server = ''
|
||||||
continue
|
continue
|
||||||
if not server:
|
if not netrange and any(line.startswith, self._netrange):
|
||||||
|
netrange = ':'.join(line.split(':')[1:]).strip()
|
||||||
|
if not server and not netrange:
|
||||||
continue
|
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 netname and any(line.startswith, self._netname):
|
||||||
|
netname = ':'.join(line.split(':')[1:]).strip()
|
||||||
elif not updated and any(line.startswith, self._updated):
|
elif not updated and any(line.startswith, self._updated):
|
||||||
s = ':'.join(line.split(':')[1:]).strip()
|
s = ':'.join(line.split(':')[1:]).strip()
|
||||||
updated = _('updated %s') % s
|
updated = _('updated %s') % s
|
||||||
@ -160,9 +179,11 @@ class Internet(callbacks.Plugin):
|
|||||||
url = _(' <registered by %s>') % line.split(':')[1].strip()
|
url = _(' <registered by %s>') % line.split(':')[1].strip()
|
||||||
elif line == 'Not a valid ID pattern':
|
elif line == 'Not a valid ID pattern':
|
||||||
url = ''
|
url = ''
|
||||||
if server and status:
|
if (server or netrange) and status:
|
||||||
|
entity = server or 'Net range %s%s' % \
|
||||||
|
(netrange, ' (%s)' % netname if netname else '')
|
||||||
info = filter(None, [status, created, updated, expires])
|
info = filter(None, [status, created, updated, expires])
|
||||||
s = format(_('%s%s is %L.'), server, url, info)
|
s = format(_('%s%s is %L.'), entity, url, info)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
else:
|
else:
|
||||||
irc.error(_('I couldn\'t find such a domain.'))
|
irc.error(_('I couldn\'t find such a domain.'))
|
||||||
|
@ -43,6 +43,8 @@ class InternetTestCase(PluginTestCase):
|
|||||||
self.assertNotError('internet whois microsoft.com')
|
self.assertNotError('internet whois microsoft.com')
|
||||||
self.assertNotError('internet whois inria.fr')
|
self.assertNotError('internet whois inria.fr')
|
||||||
self.assertNotError('internet whois slime.com.au')
|
self.assertNotError('internet whois slime.com.au')
|
||||||
|
self.assertNotError('internet whois 8.8.8.8')
|
||||||
|
self.assertNotError('internet whois net')
|
||||||
|
|
||||||
|
|
||||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user