From 02808e297731c716f8c80cf638842a9beaa20de5 Mon Sep 17 00:00:00 2001 From: Mael G Date: Sun, 28 Jul 2019 15:49:52 -0400 Subject: [PATCH] Ipv6 iplocalise backup relaod --- cogs/utility.py | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index 5a0859a..6bf639e 100755 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -7,7 +7,7 @@ import urllib import discord import requests from discord.ext import commands - +import socket class Utility(commands.Cog): """Commandes utilitaires.""" @@ -197,7 +197,8 @@ class Utility(commands.Cog): """---------------------------------------------------------------------""" @commands.command(name='iplocalise', pass_context=True) - async def _iplocalise(self, ctx, ipaddress): + async def _iplocalise(self, ctx, ipaddress, iptype=""): + realipaddress = ipaddress """Recup headers.""" if ipaddress.startswith("http://"): if ipaddress[-1:] == '/': @@ -207,45 +208,41 @@ class Utility(commands.Cog): if ipaddress[-1:] == '/': ipaddress = ipaddress[:-1] ipaddress = ipaddress.split("https://")[1] + + if(iptype=="ipv6" or iptype=="v6"): + try: + ipaddress = socket.getaddrinfo(ipaddress, None, socket.AF_INET6)[1][4][0] + except Exception as e: + await ctx.send("Erreur, cette adresse n'est pas disponible en IPv6.") + print(e) + return iploading = await ctx.send("_réfléchis..._") ipapi = urllib.request.urlopen("http://ip-api.com/json/" + ipaddress) ipinfo = json.loads(ipapi.read().decode()) if ipinfo["status"] != "fail": - if ipinfo['org']: - org = ipinfo['org'] - else: - org = 'n/a' - if ipinfo['query']: - ip = ipinfo['query'] - else: - ip = 'n/a' + embed = discord.Embed(title=f"Informations pour ``{realipaddress}`` *`({ipinfo['query']})`*", color=0x5858d7) + + if ipinfo['org']: + embed.add_field(name="Appartient à :", value=ipinfo['org'], inline = False) if ipinfo['city']: - city = ipinfo['city'] - else: - city = 'n/a' + embed.add_field(name="Se situe à :", value=ipinfo['city'], inline = True) - if ipinfo['regionName']: - regionName = ipinfo['regionName'] - else: - regionName = 'n/a' if ipinfo['country']: - country = ipinfo['country'] - else: - country = 'n/a' + if ipinfo['regionName']: + regionName = ipinfo['regionName'] + else: + regionName = "N/A" + embed.add_field(name="Region :", value=f"{regionName} ({ipinfo['country']})", inline = True) - embed = discord.Embed(title=f"Informations pour {ipaddress} *`({ip})`*", color=0x5858d7) - embed.add_field(name="Appartient à :", value=org, inline = False) - embed.add_field(name="Se situe à :", value=city, inline = True) - embed.add_field(name="Region :", value=f"{regionName} ({country})", inline = True) embed.set_thumbnail(url=f"https://www.countryflags.io/{ipinfo['countryCode']}/flat/64.png") await ctx.send(embed=embed) else: - await ctx.send(content=f"Erreur, impossible d'avoir des informations sur l'adresse IP {ipinfo['query']}") + await ctx.send(content=f"Erreur, impossible d'avoir des informations sur l'adresse IP ``{ipinfo['query']}``") await iploading.delete() """---------------------------------------------------------------------""" @@ -257,6 +254,7 @@ class Utility(commands.Cog): adresse = "http://" + adresse 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)) + elif adresse.startswith("http://") or adresse.startswith("https://") or adresse.startswith("ftp://"): try: get = urllib.request.urlopen(adresse, timeout = 1)