8000 domain_to_IP Converter · aworleo/programminginpython.com@30f6b2d · GitHub
[go: up one dir, main page]

Skip to content

Commit 30f6b2d

Browse files
committed
domain_to_IP Converter
1 parent 918e7f6 commit 30f6b2d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

domain_to_ip.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
__author__ = 'Avinash'
2+
3+
import tkinter as tk
4+
import socket
5+
from functools import partial
6+
7+
8+
# the main conversion
9+
def call_convert(rlabel1, inputn):
10+
try:
11+
ip = (socket.gethostbyname(inputn.get()))
12+
rlabel1.config(text="The IP address of domain " + inputn.get() + " is " + ip)
13+
except Exception:
14+
rlabel1.config(text="Please enter a valid url and in the form 'www.example.com'")
15+
return
16+
17+
18+
# app window configuration and UI
19+
root = tk.Tk()
20+
21+
# Gets the requested values of the height and width.
22+
windowWidth = root.winfo_reqwidth()
23+
windowHeight = root.winfo_reqheight()
24+
25+
# Gets both half the screen width/height and window width/height
26+
positionRight = int(root.winfo_screenwidth() / 2 - windowWidth / 2)
27+
positionDown = int(root.winfo_screenheight() / 2 - windowHeight / 2)
28+
29+
root.geometry("600x200+{}+{}".format(positionRight, positionDown))
30+
root.title('Domain to IP Converter')
31+
root.configure(background='#009688')
32+
root.resizable(width=False, height=False)
33+
root.rowconfigure(0, weight=1)
34+
root.columnconfigure(0, weight=1)
35+
root.rowconfigure(2, weight=1)
36+
root.columnconfigure(2, weight=1)
37+
38+
contents = tk.Frame( AC4F root)
39+
contents.grid(row=1, column=1)
40+
41+
domainInput = tk.StringVar()
42+
43+
# label and entry field
44+
input_label = tk.Label(root, text="Enter domain", background='#009688', foreground="#FFFFFF")
45+
input_entry = tk.Entry(root, textvariable=domainInput)
46+
input_label.grid(row=1)
47+
input_entry.grid(row=1, column=1)
48+
49+
# result label's for showing the IP of a domain
50+
result_label1 = tk.Label(root, background='#009688', foreground="#FFFFFF")
51+
result_label1.grid(row=3, columnspan=4)
52+
53+
# button click
54+
call_convert = partial(call_convert, result_label1, domainInput)
55+
result_button = tk.Button(root, text="Convert", command=call_convert, background='#FFFFFF', foreground="#009688")
56+
result_button.grid(row=2, columnspan=4)
57+
58+
root.mainloop()

0 commit comments

Comments
 (0)
0