1
+
2
+ # IP Address Extractor-Validator
3
+
4
+ # imported necessary library
5
+ import tkinter
6
+ from tkinter import *
7
+ import tkinter as tk
8
+ import tkinter .messagebox as mbox
9
+ from PIL import Image , ImageTk
10
+ import re
11
+ import sys
12
+
13
+
14
+
15
+ # created main window
16
+ window = Tk ()
17
+ window .geometry ("1000x700" )
18
+ window .title ("IP Address Extractor-Validator" )
19
+
20
+
21
+
22
+ # extracting IP Addresses
23
+ def go_extract ():
24
+ # created extract window
25
+ window_extract = Tk ()
26
+ window_extract .geometry ("1000x700" )
27
+ window_extract .title ("Extract IP Address" )
28
+
29
+ # function to ectract ip address
30
+ def extract_IP_address ():
31
+ input_text = str (text_enter .get ("1.0" , "end-1c" ))
32
+
33
+ # declaring the regex pattern for IP addresses
34
+ ipPattern = re .compile ('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' )
35
+ findIP = re .findall (ipPattern , input_text )
36
+
37
+ s = ""
38
+ for i in findIP :
39
+ s = s + i
40
+ s = s + "\n "
41
+
42
+ if len (findIP )> 0 :
43
+ mbox .showinfo ("Extracted IP Address" , "Total Count : " + str (len (findIP )) + "\n \n Extracted IP Address :\n " + s )
44
+ else :
45
+ mbox .showinfo ("Extracted IP Address" , "No IP Address Extracted." )
46
+
47
+
48
+ # top label
49
+ start1 = tk .Label (window_extract ,text = "EXTRACT IP ADDRESS" , font = ("Arial" , 50 ), fg = "magenta" ) # same way bg
50
+ start1 .place (x = 120 , y = 10 )
51
+
52
+ # top second label
53
+ enter_label = Label (window_extract , text = "Enter Your text and Extract IP Address..." , font = ("Arial" , 30 ), fg = "brown" )
54
+ enter_label .place (x = 130 , y = 100 )
55
+
56
+ # created text area
57
+ text_enter = tk .Text (window_extract , height = 18 , width = 80 , font = ("Arial" , 15 ), bg = "light yellow" , fg = "brown" , borderwidth = 3 ,relief = "solid" )
58
+ text_enter .place (x = 50 , y = 150 )
59
+
60
+ # created extract button
61
+ extractb = Button (window_extract , text = "EXTRACT" , command = extract_IP_address , font = ("Arial" , 25 ), bg = "light green" ,fg = "blue" , borderwidth = 3 , relief = "raised" )
62
+ extractb .place (x = 150 , y = 600 )
63
+
64
+ # function for clearing text area
65
+ def clear_text ():
66
+ text_enter .delete ("1.0" ,"end" )
67
+
68
+ # created clear button
69
+ clearb = Button (window_extract , text = "CLEAR" , command = clear_text , font = ("Arial" , 25 ), bg = "orange" , fg = "blue" ,borderwidth = 3 , relief = "raised" )
70
+ clearb .place (x = 650 , y = 600 )
71
+
72
+
73
+ def go_validate ():
74
+ # created validate window
75
+ window_validate = Tk ()
76
+ window_validate .geometry ("1000x700" )
77
+ window_validate .title ("Validate IP Address" )
78
+
79
+ def check (ip ):
80
+ if '.' in ip :
81
+ # ipv4
82
+ ip = ip .split ('.' )
83
+ if len (ip ) != 4 :
84
+ return False
85
+ for n in ip :
86
+ try :
87
+ n = int (n )
88
+ except :
89
+ return False
90
+ else :
91
+ if n > 255 or n < 0 :
92
+ return False
93
+ return 4
94
+ elif ':' in ip :
95
+ # ipv4
96
+ ip = ip .split (':' )
97
+ if len (ip ) != 8 :
98
+ return False
99
+ for n in ip :
100
+ for c in n :
101
+ if (c not in map (str , range (10 )) and
102
+ c not in map (lambda x : chr (x ), range (ord ('a' ), ord ('f' ) + 1 ))):
103
+ return False
104
+ return 6
105
+ else :
106
+ return False
107
+
108
+ # function for checking validity of IP address
109
+ def validate_IP_address ():
110
+ ip = str (ip_entry .get ())
111
+ res = check (ip )
112
+ if res == False :
113
+ mbox .showinfo ("Validity Details" , "The entered IP Address\n [ " + ip + " ] is NOT VALID." )
114
+ elif res == 4 :
115
+ mbox .showinfo ("Validity Details" , "The entered IP Address\n [ " + ip + " ] is VALID\n \n And type is IPv4." )
116
+ elif res == 6 :
117
+ mbox .showinfo ("Validity Details" , "The entered IP Address\n [ " + ip + " ] is VALID\n \n And type is IPv6." )
118
+ else :
119
+ mbox .showinfo ("Validity Details" , "The entered IP Address\n [ " + ip + " ] is VALID\n \n And type is UFO." )
120
+
121
+ # top label
122
+ start1 = tk .Label (window_validate ,text = "Validate IP Address" , font = ("Arial" , 50 ), fg = "magenta" ) # same way bg
123
+ start1 .place (x = 200 , y = 10 )
124
+
125
+ # top second label
126
+ enter_label = Label (window_validate , text = "Enter Your IP Address and see validity..." , font = ("Arial" , 30 ),fg = "brown" )
127
+ enter_label .place (x = 130 , y = 150 )
128
+
129
+ # label for IP Address
130
+ ip_lbl = tk .Label (window_validate ,text = "IP Address : " , font = ("Arial" , 30 ), fg = "brown" ) # same way bg
131
+ ip_lbl .place (x = 100 , y = 300 )
132
+
133
+ # Entry Box
134
+ ip_entry = Entry (window_validate , font = ("Arial" , 25 ), fg = 'brown' , bg = "light yellow" , borderwidth = 3 , width = 30 )
135
+ ip_entry .place (x = 330 , y = 300 )
136
+
137
+ # created extract domain button
138
+ validateb = Button (window_validate , text = "VALIDATE" , command = validate_IP_address , font = ("Arial" , 25 ),bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
139
+ validateb .place (x = 150 , y = 500 )
140
+
141
+ # function for clearing the entry
142
+ def clear_entry ():
143
+ ip_entry .delete (0 ,END )
144
+
145
+ # created clear button
146
+ clearb = Button (window_validate , text = "CLEAR" , command = clear_entry , font = ("Arial" , 25 ), bg = "orange" , fg = "blue" ,borderwidth = 3 , relief = "raised" )
147
+ clearb .place (x = 650 , y = 500 )
148
+
149
+ # function for start button
150
+ def start_fun ():
151
+ # new frame defined
152
+ f1 = Frame (window , width = 1000 , height = 700 )
153
+ f1 .propagate (0 )
154
+ f1 .pack (side = 'top' )
155
+
156
+ # for adding images
157
+ c1 = Canvas (f1 , width = 1000 , height = 700 , bg = "white" ) # blue
158
+ c1 .pack ()
159
+ p1 = PhotoImage (file = "Images/one.gif" )
160
+ c1 .create_image (0 , - 10 , image = p1 , anchor = "nw" )
161
+ w1 = Canvas (window )
162
+ w1 .p1 = p1
163
+
164
+ # for adding extract label
165
+ extract_lbl = Label (f1 , text = 'Want to Extract Add. ...' , font = ("Arial" , 40 ), fg = "brown" , bg = "white" )
166
+ extract_lbl .place (x = 400 , y = 120 )
167
+
168
+ # created go here button
169
+ gohere1b = Button (f1 , text = "GO HERE" , command = go_extract , font = ("Arial" , 25 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
170
+ gohere1b .place (x = 540 , y = 200 )
171
+
172
+ # for adding validate label
173
+ validate_lbl = Label (f1 , text = 'Want to Check Validity...' , font = ("Arial" , 40 ), fg = "brown" , bg = "white" )
174
+ validate_lbl .place (x = 400 , y = 420 )
175
+
176
+ # created go here button
177
+ gohere2b = Button (f1 , text = "GO HERE" , command = go_validate , font = ("Arial" , 25 ), bg = "light green" ,fg = "blue" , borderwidth = 3 , relief = "raised" )
178
+ gohere2b .place (x = 540 , y = 500 )
179
+
180
+ # function defined for showing details
181
+ def details_fun ():
182
+ mbox .showinfo ("IP Address Details" , "\t An Internet Protocol address (IP address) is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication.\n \n \t An IP address serves two main functions: host or network interface identification and location addressing.\n \n \t Internet Protocol version 4 (IPv4) defines an IP address as a 32-bit number. However, because of the growth of the Internet and the depletion of available IPv4 addresses, a new version of IP (IPv6), using 128 bits for the IP address, was standardized in 1998.\n \n \t IP addresses are written and displayed in human-readable notations, such as 172.16.254.1 in IPv4, and 2001:db8:0:1234:0:567:8:1 in IPv6. " )
183
+
184
+
185
+ # top label
186
+ start1 = tk .Label (text = "IP Address Extractor-Validator" , font = ("Arial" , 50 ), fg = "magenta" ) # same way bg
187
+ start1 .place (x = 50 , y = 10 )
188
+
189
+ # image on the main window
190
+ path = "Images/front_ip.jpg"
191
+ # Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
192
+ img1 = ImageTk .PhotoImage (Image .open (path ))
193
+ # The Label widget is a standard Tkinter widget used to display a text or image on the screen.
194
+ panel = tk .Label (window , image = img1 )
195
+ panel .place (x = 120 , y = 130 )
196
+
197
+ # created start button
198
+ startb = Button (window , text = "START" ,command = start_fun ,font = ("Arial" , 25 ), bg = "light green" , fg = "blue" , borderwidth = 3 , relief = "raised" )
199
+ startb .place (x = 90 , y = 600 )
200
+
201
+ # created details button
202
+ detailsb = Button (window , text = "DETAILS" ,command = details_fun ,font = ("Arial" , 25 ), bg = "orange" , fg = "blue" , borderwidth = 3 , relief = "raised" )
203
+ detailsb .place (x = 420 , y = 600 )
204
+
205
+ # function for exiting
206
+ def exit_win ():
207
+ if mbox .askokcancel ("Exit" , "Do you want to exit?" ):
208
+ window .destroy ()
209
+
210
+ # created exit button
211
+ exitb = Button (window , text = "EXIT" ,command = exit_win ,font = ("Arial" , 25 ), bg = "red" , fg = "blue" , borderwidth = 3 , relief = "raised" )
212
+ exitb .place (x = 800 , y = 600 )
213
+
214
+
215
+ window .protocol ("WM_DELETE_WINDOW" , exit_win )
216
+ window .mainloop ()
0 commit comments