-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
149 lines (121 loc) · 4.94 KB
/
app.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
from libs.as_info import ASInfo
from libs import ip
from tkinter import *
from tkinter.ttk import *
import tkinter.font as font
#from tkinter_functions import display_peers
# writing code needs to
# create the main window of
# the application creating
# main window object named root
root = Tk()
#root['background']='grey'##856ff8
myFont = font.Font(family='Courier')
# giving title to the main window
root.title("AS Information")
root.geometry('720x460')
#target_asn = StringVar()
as_entry_label = Label(root,text= "Enter ASN:")
as_entry_label.grid(column=1,row=1,sticky='ew')
as_entry = Entry(root)
as_entry.grid(column= 2, row = 1,sticky='ew')
ip_entry_label = Label(root,text = "Get ASN from IP address: ")
ip_entry_label.grid(column = 4, row = 1,sticky='ew')
ip_entry = Entry(root)
ip_entry.grid(column=5, row = 1,sticky='ew')
def ip_enter_clicked():
text_display.delete("1.0", "end")
if ip_entry.get() == "":
text_display.insert("end", "No IP address entered")
else:
ip_entered = ip_entry.get()
ip_address = ip.ipaddress_check(ip_entered)
ip_data = ip.bgp_ip_lookup(ip_address)
asn = ip_data['data']['prefixes'][0]['asn']['asn']
display_text = 'ASN: ' + str(asn)
text_display.insert("end", display_text)
ip_enter_btn = Button(root,text = "Enter",command = ip_enter_clicked)
ip_enter_btn.grid(column=6, row = 1,sticky='ew')
asns = [123,1222,333]
as_info_objects = []
# function to display user text when
# button is clicked
def enter_clicked():
text_display.delete("1.0", "end")
if as_entry.get() == "":
text_display.insert("end","No ASN entered")
else:
new_asn = int(as_entry.get())
new_asn_object = ASInfo(new_asn)
as_info_objects.append(new_asn_object)
asns.append(new_asn)
# button widget with red color text inside
enter_btn = Button(root, text = "Enter" , command=enter_clicked)
# Set Button Grid
enter_btn.grid(column=3, row=1,sticky='ew')
def display_peers():
text_display.delete("1.0", "end")
if as_info_objects:
asn = as_info_objects[-1] # Get the last entered ASN
# Display the relevant information based on the ASN
display_text = f"Displaying peers for ASN {asn.asn}\n"
display_text += asn.print_peers()
text_display.insert("end", display_text)
else:
text_display.insert("end", "No ASN entered yet.\n")
#print(f"Displaying peers for ASN {asn.asn}")
#asn.print_peers()
def display_upstreams():
text_display.delete("1.0", "end")
if as_info_objects:
asn = as_info_objects[-1] # Get the last entered ASN
# Display the relevant information based on the ASN
display_text = f"Displaying upstreams for ASN {asn.asn}\n"
display_text += asn.print_upstreams()
text_display.insert("end", display_text)
else:
text_display.insert("end", "No ASN entered yet.\n")
def display_downstreams():
text_display.delete("1.0", "end")
if as_info_objects:
asn = as_info_objects[-1] # Get the last entered ASN
# Display the relevant information based on the ASN
display_text = f"Displaying downstreams for ASN {asn.asn}\n"
display_text += asn.print_downstreams()
text_display.insert("end", display_text)
else:
text_display.insert("end", "No ASN entered yet.\n")
def display_ixs():
text_display.delete("1.0", "end")
if as_info_objects:
asn = as_info_objects[-1] # Get the last entered ASN
# Display the relevant information based on the ASN
display_text = f"Displaying IXPs for ASN {asn.asn}\n"
display_text += asn.print_ixs()
text_display.insert("end", display_text)
else:
text_display.insert("end", "No ASN entered yet.\n")
def display_details():
text_display.delete("1.0", "end")
if as_info_objects:
asn = as_info_objects[-1]
display_text = asn.print_details()
text_display.insert("end",display_text)
else:
text_display.insert("end", "No ASN entered yet.\n")
#display_details_btn = Button(root,text="Display ASN Details",command = display_details)
#display_details_btn.grid(column=1,row=2)
display_peers_btn = Button(root,text="Display Peers",command = display_peers)
display_peers_btn.grid(column=2,row=2,sticky='ew')
display_upstreams_btn = Button(root,text="Display Upstreams",command = display_upstreams)
display_upstreams_btn.grid(column=3,row=2,sticky='ew')
display_downstreams_btn = Button(root,text="Display Downstreams",command = display_downstreams)
display_downstreams_btn.grid(column=4,row=2,sticky='ew')
display_ixs_btn = Button(root,text="Display IXP's",command = display_ixs)
display_ixs_btn.grid(column=5,row=2,sticky='ew')
display_details_btn = Button(root,text="Display Details",command = display_details)
display_details_btn.grid(column=1,row=2,sticky='ew')
#need a display details button
text_display = Text(root)
text_display.grid(column = 1,row=7,columnspan=5,sticky='w')
root.mainloop()