-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmybot.py
48 lines (34 loc) · 1.19 KB
/
mybot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import discord
from discord.ext import commands
from netmiko import Netmiko
TOKEN = "<paste_your_token_here"
client = commands.Bot(command_prefix = "$")
@client.event
async def on_ready():
print("I am ready !..")
@client.command(name= "get_interface")
async def get_interface(ctx,arg1 ,interface):
net_connect = Netmiko(
host = arg1,
username = "cisco",
password = "admin",
device_type = "cisco_ios")
output = net_connect.send_command_expect("show ip interface brief", use_genie=True)
parsed = output["interface"][interface]["ip_address"]
net_connect.disconnect()
await ctx.send(parsed)
@client.command(name="get_interface_status")
async def get_interface_status(ctx,arg1):
net_connect = Netmiko(
host = arg1,
username = "cisco",
password = "admin",
device_type = "cisco_ios")
parsed=""
output = net_connect.send_command_expect("show ip interface brief", use_genie=True)
for n in output["interface"]:
status = output["interface"][n]["status"]
parsed += n + " = " + status + "\n"
net_connect.disconnect()
await ctx.send(parsed)
client.run(TOKEN)