Ipv6 iplocalise backup relaod
This commit is contained in:
parent
3a2bfc0220
commit
02808e2977
1 changed files with 23 additions and 25 deletions
|
@ -7,7 +7,7 @@ import urllib
|
||||||
import discord
|
import discord
|
||||||
import requests
|
import requests
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
|
import socket
|
||||||
|
|
||||||
class Utility(commands.Cog):
|
class Utility(commands.Cog):
|
||||||
"""Commandes utilitaires."""
|
"""Commandes utilitaires."""
|
||||||
|
@ -197,7 +197,8 @@ class Utility(commands.Cog):
|
||||||
"""---------------------------------------------------------------------"""
|
"""---------------------------------------------------------------------"""
|
||||||
|
|
||||||
@commands.command(name='iplocalise', pass_context=True)
|
@commands.command(name='iplocalise', pass_context=True)
|
||||||
async def _iplocalise(self, ctx, ipaddress):
|
async def _iplocalise(self, ctx, ipaddress, iptype=""):
|
||||||
|
realipaddress = ipaddress
|
||||||
"""Recup headers."""
|
"""Recup headers."""
|
||||||
if ipaddress.startswith("http://"):
|
if ipaddress.startswith("http://"):
|
||||||
if ipaddress[-1:] == '/':
|
if ipaddress[-1:] == '/':
|
||||||
|
@ -207,45 +208,41 @@ class Utility(commands.Cog):
|
||||||
if ipaddress[-1:] == '/':
|
if ipaddress[-1:] == '/':
|
||||||
ipaddress = ipaddress[:-1]
|
ipaddress = ipaddress[:-1]
|
||||||
ipaddress = ipaddress.split("https://")[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..._")
|
iploading = await ctx.send("_réfléchis..._")
|
||||||
ipapi = urllib.request.urlopen("http://ip-api.com/json/" + ipaddress)
|
ipapi = urllib.request.urlopen("http://ip-api.com/json/" + ipaddress)
|
||||||
ipinfo = json.loads(ipapi.read().decode())
|
ipinfo = json.loads(ipapi.read().decode())
|
||||||
|
|
||||||
if ipinfo["status"] != "fail":
|
if ipinfo["status"] != "fail":
|
||||||
if ipinfo['org']:
|
|
||||||
org = ipinfo['org']
|
|
||||||
else:
|
|
||||||
org = 'n/a'
|
|
||||||
|
|
||||||
if ipinfo['query']:
|
if ipinfo['query']:
|
||||||
ip = ipinfo['query']
|
embed = discord.Embed(title=f"Informations pour ``{realipaddress}`` *`({ipinfo['query']})`*", color=0x5858d7)
|
||||||
else:
|
|
||||||
ip = 'n/a'
|
if ipinfo['org']:
|
||||||
|
embed.add_field(name="Appartient à :", value=ipinfo['org'], inline = False)
|
||||||
|
|
||||||
if ipinfo['city']:
|
if ipinfo['city']:
|
||||||
city = ipinfo['city']
|
embed.add_field(name="Se situe à :", value=ipinfo['city'], inline = True)
|
||||||
else:
|
|
||||||
city = 'n/a'
|
|
||||||
|
|
||||||
if ipinfo['regionName']:
|
|
||||||
regionName = ipinfo['regionName']
|
|
||||||
else:
|
|
||||||
regionName = 'n/a'
|
|
||||||
|
|
||||||
if ipinfo['country']:
|
if ipinfo['country']:
|
||||||
country = ipinfo['country']
|
if ipinfo['regionName']:
|
||||||
else:
|
regionName = ipinfo['regionName']
|
||||||
country = 'n/a'
|
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")
|
embed.set_thumbnail(url=f"https://www.countryflags.io/{ipinfo['countryCode']}/flat/64.png")
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
else:
|
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()
|
await iploading.delete()
|
||||||
|
|
||||||
"""---------------------------------------------------------------------"""
|
"""---------------------------------------------------------------------"""
|
||||||
|
@ -257,6 +254,7 @@ class Utility(commands.Cog):
|
||||||
adresse = "http://" + adresse
|
adresse = "http://" + adresse
|
||||||
if len(adresse) > 200:
|
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.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://"):
|
elif adresse.startswith("http://") or adresse.startswith("https://") or adresse.startswith("ftp://"):
|
||||||
try:
|
try:
|
||||||
get = urllib.request.urlopen(adresse, timeout = 1)
|
get = urllib.request.urlopen(adresse, timeout = 1)
|
||||||
|
|
Loading…
Reference in a new issue