This commit is contained in:
0xd3d0c3d 2021-12-11 20:44:31 -06:00
parent 7dade33bab
commit 3cc72222cf
2 changed files with 84 additions and 0 deletions

@ -37,6 +37,7 @@ includes =
plugins.ud_plugin
plugins.figlet_plugin
plugins.soundcloud_plugin
plugins.isup_plugin
autojoins =
${#}tcpdirect

83
plugins/isup_plugin.py Normal file

@ -0,0 +1,83 @@
# -*- coding: utf-8 -*-
from irc3.plugins.command import command
import irc3
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError
###########################################################################################
###########################################################################################
@irc3.plugin
class Plugin:
#######################################################################################
#######################################################################################
def __init__(self, bot):
self.bot = bot
#######################################################################################
#######################################################################################
def isup_check(self, domain_or_ip):
msg=''
try:
url=f'http://{domain_or_ip}'
try:
req = Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
}
)
response=urlopen(req,timeout=10).read().decode('utf-8')
except HTTPError as e:
msg='down -> could not complete the request. error code: {}'.format(e.code)
except URLError as e:
msg='down -> failed to reach the server. reason: {}'.format(e.reason)
else:
msg='up -> site is communicating'
except:
url=f'https://{domain_or_ip}'
try:
req = Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
}
)
response=urlopen(req,timeout=10).read().decode('utf-8')
except HTTPError as e:
msg='down -> could not complete the request. error code: {}'.format(e.code)
except URLError as e:
msg='down -> failed to reach the server. reason: {}'.format(e.reason)
else:
msg='up -> site is communicating'
finally:
return msg
#######################################################################################
#######################################################################################
@command(permission='view')
def isup(self, mask, target, args):
"""isup domain
%%isup <domain>
"""
domain=args.get('<domain>')
domain_noise=domain
try:
domain_noise=domain.split('://')[1]
except:
pass
try:
if not domain_noise:
domain_noise=domain[:domain.find('.')+domain[domain.find('.')+1:].find('/')+1].split('://')[1]
except:
if not domain_noise.find('/')==-1:
domain_noise=domain[:domain.find('.')+domain[domain.find('.')+1:].find('/')+1].split('://')[0]
if domain_noise[-1]=="/": domain_noise=domain_noise[:-1]
if domain_noise.replace('.','').isnumeric() and (len(domain_noise)-3) == len(domain_noise.replace('.','')):
domain=domain_noise
elif domain_noise.find('/') == -1 and not domain_noise.find('.') == -1 and domain_noise.replace('.','').isalnum():
domain=domain_noise
else:
self.bot.privmsg(target,self.bot.emo("{}: doesn't sanitize towards a valid domain/ip".format(domain)))
return
self.bot.privmsg(target,self.bot.emo("{} {}".format(domain,self.isup_check(domain))))
###########################################################################################
###########################################################################################