From ecdde52ca3cc4b8f226c4a8d9a2c49fac3b7eac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20G?= Date: Tue, 18 Aug 2020 15:39:23 -0400 Subject: [PATCH] iplocalise bug fix + bgp.he.net link --- cogs/utility.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/cogs/utility.py b/cogs/utility.py index f66d5ee..29fdaa1 100755 --- a/cogs/utility.py +++ b/cogs/utility.py @@ -7,6 +7,7 @@ import ipinfo as ipinfoio from ipwhois.net import Net from ipwhois.asn import IPASN +import ipwhois import discord import requests @@ -234,9 +235,14 @@ class Utility(commands.Cog): iploading = await ctx.send("_Récupération des informations..._") - net = Net(ipaddress) - obj = IPASN(net) - ipinfo = obj.lookup() + try: + net = Net(ipaddress) + obj = IPASN(net) + ipinfo = obj.lookup() + except ipwhois.exceptions.IPDefinedError: + await ctx.send("Cette IP est reservée à un usage local selon la RFC 1918. Impossible d'avoir des informations supplémentaires à son propos.") + await iploading.delete() + return try: iphostname = socket.gethostbyaddr(ipaddress)[0] @@ -256,9 +262,10 @@ class Utility(commands.Cog): embed = discord.Embed(title=f"Informations pour ``{realipaddress} ({ipaddress})``", color=0x5858d7) if(api_result): - embed.add_field(name="Appartient à :", value=f"{details.org}") + asn = details.org.split(" ")[0] + embed.add_field(name="Appartient à :", value=f"[{details.org}](https://bgp.he.net/{asn})") else: - embed.add_field(name="Appartient à :", value=f"{ipinfo['asn_description']} (AS{ipinfo['asn']})", inline = False) + embed.add_field(name="Appartient à :", value=f"{ipinfo['asn_description']} ([AS{ipinfo['asn']}](https://bgp.he.net/{ipinfo['asn']}))", inline = False) embed.add_field(name="RIR :", value=f"{ipinfo['asn_registry']}", inline = True)