iplocalise bug fix + bgp.he.net link

This commit is contained in:
Mael G. 2020-08-18 15:39:23 -04:00
parent 534a78e447
commit ecdde52ca3

View file

@ -7,6 +7,7 @@ import ipinfo as ipinfoio
from ipwhois.net import Net from ipwhois.net import Net
from ipwhois.asn import IPASN from ipwhois.asn import IPASN
import ipwhois
import discord import discord
import requests import requests
@ -234,9 +235,14 @@ class Utility(commands.Cog):
iploading = await ctx.send("_Récupération des informations..._") iploading = await ctx.send("_Récupération des informations..._")
net = Net(ipaddress) try:
obj = IPASN(net) net = Net(ipaddress)
ipinfo = obj.lookup() 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: try:
iphostname = socket.gethostbyaddr(ipaddress)[0] iphostname = socket.gethostbyaddr(ipaddress)[0]
@ -256,9 +262,10 @@ class Utility(commands.Cog):
embed = discord.Embed(title=f"Informations pour ``{realipaddress} ({ipaddress})``", color=0x5858d7) embed = discord.Embed(title=f"Informations pour ``{realipaddress} ({ipaddress})``", color=0x5858d7)
if(api_result): 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: 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) embed.add_field(name="RIR :", value=f"{ipinfo['asn_registry']}", inline = True)