improve getheaders
This commit is contained in:
parent
534a78e447
commit
175174757b
1 changed files with 35 additions and 60 deletions
|
@ -3,6 +3,7 @@ import json
|
||||||
import pytz
|
import pytz
|
||||||
import random
|
import random
|
||||||
import urllib
|
import urllib
|
||||||
|
import aiohttp
|
||||||
import ipinfo as ipinfoio
|
import ipinfo as ipinfoio
|
||||||
|
|
||||||
from ipwhois.net import Net
|
from ipwhois.net import Net
|
||||||
|
@ -246,10 +247,12 @@ class Utility(commands.Cog):
|
||||||
# IPINFO api
|
# IPINFO api
|
||||||
api_result = True
|
api_result = True
|
||||||
try:
|
try:
|
||||||
access_token = open('ipinfoio.key').read()
|
with open('ipinfoio.key') as k:
|
||||||
|
access_token = k.read().replace("\n", "")
|
||||||
handler = ipinfoio.getHandler(access_token)
|
handler = ipinfoio.getHandler(access_token)
|
||||||
details = handler.getDetails(ipaddress)
|
details = handler.getDetails(ipaddress)
|
||||||
except:
|
except Exception as e:
|
||||||
|
await ctx.send(e)
|
||||||
api_result = False
|
api_result = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -280,64 +283,36 @@ class Utility(commands.Cog):
|
||||||
await iploading.delete()
|
await iploading.delete()
|
||||||
|
|
||||||
"""---------------------------------------------------------------------"""
|
"""---------------------------------------------------------------------"""
|
||||||
@commands.command(name='getheaders', pass_context=True)
|
|
||||||
async def _getheaders(self, ctx, *, adresse):
|
@commands.command(name='getheaders')
|
||||||
"""Recuperer les HEADERS :d"""
|
async def _getheaders(self, ctx: commands.Context, addr: str):
|
||||||
if adresse.startswith("http://") != True and adresse.startswith("https://") != True:
|
if (addr.startswith('http') or addr.startswith('ftp')) is not True:
|
||||||
adresse = "http://" + adresse
|
addr = f"http://{addr}"
|
||||||
if len(adresse) > 200:
|
|
||||||
await ctx.send("{0} Essaye d'entrer une adresse de moins de 200 caractères plutôt.".format(ctx.author.mention))
|
await ctx.trigger_typing()
|
||||||
|
|
||||||
elif adresse.startswith("http://") or adresse.startswith("https://") or adresse.startswith("ftp://"):
|
try:
|
||||||
try:
|
async with self.bot.session.get(addr) as s:
|
||||||
get = urllib.request.urlopen(adresse, timeout = 1)
|
e = discord.Embed(
|
||||||
embed = discord.Embed(title="Entêtes de {0}".format(adresse), color=0xd75858)
|
title=f"Headers : {addr}",
|
||||||
embed.add_field(name="Code Réponse", value=get.getcode(), inline = True)
|
color=0xd75858
|
||||||
embed.set_thumbnail(url="https://http.cat/{}".format(str(get.getcode())))
|
)
|
||||||
if get.getheader('location'):
|
e.add_field(name="Status", value=s.status, inline=True)
|
||||||
embed.add_field(name="Redirection vers", value=get.getheader('location'), inline=True)
|
e.set_thumbnail(url=f"https://http.cat/{s.status}")
|
||||||
if get.getheader('server'):
|
|
||||||
embed.add_field(name="Serveur", value=get.getheader('server'), inline=True)
|
headers = dict(s.headers.items())
|
||||||
if get.getheader('content-type'):
|
headers.pop('Set-Cookie', headers)
|
||||||
embed.add_field(name="Type de contenu", value = get.getheader('content-type'), inline = True)
|
|
||||||
if get.getheader('x-content-type-options'):
|
for key, value in headers.items():
|
||||||
embed.add_field(name="x-content-type", value= get.getheader('x-content-type-options'), inline=True)
|
e.add_field(name=key, value=value, inline=True)
|
||||||
if get.getheader('x-frame-options'):
|
await ctx.send(embed=e)
|
||||||
embed.add_field(name="x-frame-options", value= get.getheader('x-frame-options'), inline=True)
|
|
||||||
if get.getheader('cache-control'):
|
except aiohttp.ClientError:
|
||||||
embed.add_field(name="Controle du cache", value = get.getheader('cache-control'), inline = True)
|
await ctx.send(
|
||||||
await ctx.send(embed=embed)
|
f"Cannot connect to host {addr}"
|
||||||
except urllib.error.HTTPError as e:
|
)
|
||||||
embed = discord.Embed(title="Entêtes de {0}".format(adresse), color=0xd75858)
|
|
||||||
embed.add_field(name="Code Réponse", value=e.getcode(), inline = True)
|
|
||||||
embed.set_thumbnail(url="https://http.cat/{}".format(str(e.getcode())))
|
|
||||||
await ctx.send(embed=embed)
|
|
||||||
print('''An error occurred: {} The response code was {}'''.format(e, e.getcode()))
|
|
||||||
except urllib.error.URLError as e:
|
|
||||||
if "No address associated" in str(e):
|
|
||||||
await ctx.send("Erreur, aucune adresse n'est associé à ce nom d'hôte.")
|
|
||||||
return
|
|
||||||
if "timed out" in str(e):
|
|
||||||
await ctx.send("Erreur, l'adresse en question dépasse le délais d'attente :(")
|
|
||||||
return
|
|
||||||
if "SSL" in str(e):
|
|
||||||
await ctx.send("Erreur avec le certificat SSL, essayez sans ``https://`` !")
|
|
||||||
return
|
|
||||||
return
|
|
||||||
if "no host":
|
|
||||||
await ctx.send("Erreur, aucun nom d'hôte n'a été donné.")
|
|
||||||
return
|
|
||||||
if "not known":
|
|
||||||
await ctx.send("Erreur, nom de l'hôte inconnu.")
|
|
||||||
return
|
|
||||||
print("ERROR @ getheaders @ urlerror : {} - adress {}".format(e, adresse))
|
|
||||||
await ctx.send('[CONTACTER ADMIN] URLError: {}'.format(e.reason))
|
|
||||||
except Exception as e:
|
|
||||||
print("ERROR @ getheaders @ Exception : {} - adress {}".format(e, adresse))
|
|
||||||
await ctx.send("{0} Impossible d'accèder à {1}, es-tu sur que l'adresse {1} est correcte et que le serveur est allumé ?".format(ctx.author.mention, adresse))
|
|
||||||
else:
|
|
||||||
await ctx.send("{0} Merci de faire commencer {1} par ``https://``, ``http://`` ou ``ftp://``.".format(ctx.author.mention, adresse))
|
|
||||||
|
|
||||||
"""---------------------------------------------------------------------"""
|
"""---------------------------------------------------------------------"""
|
||||||
@commands.command(name='peeringdb', pass_context=True)
|
@commands.command(name='peeringdb', pass_context=True)
|
||||||
async def _peeringdb(self, ctx, *, asn):
|
async def _peeringdb(self, ctx, *, asn):
|
||||||
|
|
Loading…
Reference in a new issue