This commit is contained in:
Mael G. 2020-08-19 10:33:48 -04:00
parent 5cc364480a
commit d3683ed10d
8 changed files with 288 additions and 2 deletions

0
autoinstall.sh Normal file → Executable file
View file

0
cogs/monitoring.py Normal file → Executable file
View file

View file

@ -7,12 +7,15 @@ import ipinfo as ipinfoio
import pydig
import telnetlib
from graphviz import Digraph
from ipwhois.net import Net
from ipwhois.asn import IPASN
import ipwhois
import discord
import requests
import requests, re
from discord.ext import commands
import socket
@ -325,6 +328,8 @@ class Utility(commands.Cog):
embed.add_field(name="Ooops", value="Pas de résultat")
await ctx.send(embed=embed)
"""---------------------------------------------------------------------"""
"""---------------------------------------------------------------------"""
@commands.command(name='getheaders', pass_context=True)
async def _getheaders(self, ctx, *, adresse):
@ -443,6 +448,125 @@ class Utility(commands.Cog):
await ctx.send(f"L'AS{asn} est introuvable dans la base de données de PeeringDB.")
await loadingmsg.delete()
"""---------------------------------------------------------------------"""
@commands.command(name='shroute', pass_context=True)
async def _shroute(self, ctx, srv, ipaddress):
if not srv in ["opentransit", 'he', 'att', "oregonuniv", "warian", 'csaholdigs', 'iamageeknz']:
await ctx.send("Requêtes supportées : opentransit (Orange), he (Huricanne Electric), att (AT&T), oregonuniv, warian, csaholdigs, iamageeknz")
return
print("k")
if srv == "opentransit":
host = "route-server.opentransit.net"
user = "rviews"
password = "Rviews"
lg_asn = "5511"
cmd = "show bgp {}"
elif srv == "oregonuniv":
host = "route-views.routeviews.org"
user = "rviews"
password = "none"
lg_asn = "3582"
cmd = "show bgp {}"
elif srv == "warian":
host = "route-server.warian.net"
user = "none"
password = "rviews"
lg_asn = "56911"
cmd = "show bgp ipv4 unicast {}"
elif srv == "csaholdigs": #Blacklist des fois
host = "route-views.sg.routeviews.org"
user = "none"
password = "none"
lg_asn = "45494"
cmd = "show bgp ipv4 unicast {}"
elif srv == "he": #Blacklist des fois
host = "route-server.he.net"
user = "none"
password = "none"
lg_asn = "6939"
cmd = "show bgp ipv4 unicast {}"
elif srv == "iamageeknz": #Blacklist des fois
host = "rs.as45186.net"
user = "none"
password = "none"
lg_asn = "45186"
cmd = "show bgp ipv4 unicast {}"
elif srv == "att":
host = "route-server.ip.att.net"
user = "rviews"
password = "rviews"
lg_asn = "7018"
cmd = "show route {}"
ip = ipaddress
await ctx.send("Connexion en cours au route server...")
tn = telnetlib.Telnet(host)
if user != "none":
if(srv == "att"):
tn.read_until("login: ".encode())
tn.write((user + "\n").encode())
else:
tn.read_until("Username: ".encode())
tn.write((user + "\n").encode())
if password != "none":
if(srv == "att"):
tn.read_until("Password:".encode())
tn.write((password + "\n").encode())
print("ok")
else:
tn.read_until("Password: ".encode())
tn.write((password + "\n").encode())
await ctx.send("Connecté ! Récupération des données...")
# Execution d'une commande d'information BGP
tn.write((cmd + "\n").format(ip).encode())
tn.write(chr(25).encode())
tn.write(chr(25).encode())
tn.write(chr(25).encode())
tn.write("q\n".encode())
tn.write("exit\n".encode())
await ctx.send("Données récupérées ! Traitement en cours")
# Decodage des données pour les adaptées à python
data = tn.read_all().decode("utf-8")
print(data)
# Récupération des données grâce à l'utilisation d'expression régulière (module re)
paths = {}
paths["as_list"] = re.findall(r" ([0-9][0-9 ]+),", data)
if(paths["as_list"] == []):
paths["as_list"] = re.findall(r" ([0-9][0-9 ]+)[^0-9.]", data)
if(srv == "att"):
paths["as_list"] = re.findall(r"(?<=AS path: 7018 )[0-9][0-9 ]+[^ I]", data)
as_list = paths['as_list']
g = Digraph('G', filename='hello', format='png', graph_attr={'rankdir':'LR', 'concentrate': 'true'})
for as_path in as_list:
as_path = as_path.split(" ")
as_path.reverse()
original_asn = as_path[0]
border_asn = as_path[-1]
precedent_asn = original_asn
for asn in as_path:
if asn != original_asn:
g.edge("AS" + asn, "AS" + precedent_asn)
precedent_asn = asn
if asn == border_asn:
g.edge("AS" + lg_asn, "AS" + asn)
g.render()
with open('hello.png', 'rb') as fp:
await ctx.send(file=discord.File(fp, 'hello.png'))
"""---------------------------------------------------------------------"""
@commands.command(name='git', pass_context=True)

14
hello Executable file
View file

@ -0,0 +1,14 @@
digraph G {
graph [concentrate=true rankdir=LR]
AS200780 -> AS57199
AS174 -> AS200780
AS701 -> AS174
AS3582 -> AS701
AS35280 -> AS57199
AS1299 -> AS35280
AS3267 -> AS1299
AS3582 -> AS3267
AS6461 -> AS57199
AS1403 -> AS6461
AS3582 -> AS1403
}

BIN
hello.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View file

@ -9,4 +9,5 @@ wikipedia
pillow
ipwhois
ipinfo
pydig
pydig
networkx

117
test.py Executable file
View file

@ -0,0 +1,117 @@
import telnetlib
import re
from graphviz import Digraph
srv = "he"
if srv == "opentransit":
host = "route-server.opentransit.net"
user = "rviews"
password = "Rviews"
lg_asn = "5511"
cmd = "show bgp {}"
elif srv == "oregonuniv":
host = "route-views.routeviews.org"
user = "rviews"
password = "none"
lg_asn = "3582"
cmd = "show bgp {}"
elif srv == "warian":
host = "route-server.warian.net"
user = "none"
password = "rviews"
lg_asn = "56911"
cmd = "show bgp ipv4 unicast {}"
elif srv == "csaholdigs": #Blacklist des fois
host = "route-views.sg.routeviews.org"
user = "none"
password = "none"
lg_asn = "45494"
cmd = "show bgp ipv4 unicast {}"
elif srv == "he": #Blacklist des fois
host = "route-server.he.net"
user = "none"
password = "none"
lg_asn = "6939"
cmd = "show bgp ipv4 unicast {}"
elif srv == "iamageeknz": #Blacklist des fois
host = "rs.as45186.net"
user = "none"
password = "none"
lg_asn = "45186"
cmd = "show bgp ipv4 unicast {}"
elif srv == "att":
host = "route-server.ip.att.net"
user = "rviews"
password = "rviews"
lg_asn = "7018"
cmd = "show route {}"
# Récupération de l'IP dont on veux connaitre plus d'informations
ip = input("IP : ")
# Connexion à OpenTransit
tn = telnetlib.Telnet(host)
if user != "none":
if(srv == "att"):
tn.read_until("login: ".encode())
tn.write((user + "\n").encode())
print("ok")
else:
tn.read_until("Username: ".encode())
tn.write((user + "\n").encode())
if password != "none":
if(srv == "att"):
tn.read_until("Password:".encode())
tn.write((password + "\n").encode())
print("ok")
else:
tn.read_until("Password: ".encode())
tn.write((password + "\n").encode())
# Execution d'une commande d'information BGP
tn.write((cmd + "\n").format(ip).encode())
tn.write(chr(25).encode())
tn.write(chr(25).encode())
tn.write(chr(25).encode())
tn.write("q\n".encode())
tn.write("exit\n".encode())
# Decodage des données pour les adaptées à python
data = tn.read_all().decode("utf-8")
print(data)
# Récupération des données grâce à l'utilisation d'expression régulière (module re)
paths = {}
paths["as_list"] = re.findall(r" ([0-9][0-9 ]+),", data)
if(paths["as_list"] == []):
paths["as_list"] = re.findall(r" ([0-9][0-9 ]+)[^0-9.]", data)
if(srv == "att"):
paths["as_list"] = re.findall(r"(?<=AS path: 7018 )[0-9][0-9 ]+[^ I]", data)
as_list = paths['as_list']
g = Digraph('G', filename='hello', format='png', graph_attr={'rankdir':'LR', 'concentrate': 'true'})
for as_path in as_list:
as_path = as_path.split(" ")
as_path.reverse()
original_asn = as_path[0]
border_asn = as_path[-1]
precedent_asn = original_asn
for asn in as_path:
if asn != original_asn:
g.edge("AS" + asn, "AS" + precedent_asn)
precedent_asn = asn
if asn == border_asn:
g.edge("AS" + lg_asn, "AS" + asn)
g.render()

30
test2.py Executable file
View file

@ -0,0 +1,30 @@
import networkx as nx
import matplotlib.pyplot as plt
from graphviz import Digraph
import ipinfo as ipinfoio
as_list = ['701 2914 395747', '3267 1299 395747', '3257 395747']
g = Digraph('G', filename='hello', format='png', graph_attr={'rankdir':'LR'})
lg_asn = "5511"
for as_path in as_list:
as_path = as_path.split(" ")
as_path.reverse()
original_asn = as_path[0]
border_asn = as_path[-1]
precedent_asn = original_asn
for asn in as_path:
if asn != original_asn:
g.edge("AS" + asn, "AS" + precedent_asn)
precedent_asn = asn
if asn == border_asn:
g.edge("AS" + lg_asn, "AS" + asn)
print(as_path)
print("\n")
g.render()