Create a GUI to Get Domain Information using Tkinter


In today's world, many businesses depend heavily on their online presence. Before setting up a website or purchasing a domain name, it is essential to get as much information as possible about the domain you plan to use. It may include information like domain owner, server location, IP address, WHOIS details, and much more. Therefore, in the following instruction manual, we'll guide you about creating a GUI to get domain information using Tkinter.

What is GUI?

GUI (Graphical User Interface) is a way to present data to the user in the form of interactive windows, buttons, and menus instead of traditional command-line interfaces. It allows users to interact with the computer more comfortable and intuitive by using pictures and graphics rather than text commands.

Why use Tkinter for GUI?

Tkinter is one of the most popular libraries used to create graphical user interfaces. It is a built-in library in , so there is no need to install any third-party libraries. It provides a comprehensive set of tools for creating GUIs, including text widgets, menu bars, and canvas objects, etc.

What are the key advantages of using Tkinter?

Tkinter is a library used for creating GUI applications. Here are some of the key advantages of using Tkinter −

  • It is included in − Tkinter is included in the standard distribution, which means that it is always available to use without installing any additional libraries.

  • Cross-platform compatibility − Tkinter works on all major operating systems, including Windows, macOS, and Linux.

  • Easy to learn − Tkinter has a simple and intuitive API, which makes it easy to learn and use, especially for beginners who are just starting with GUI programming.

  • Customizable widgets − Tkinter provides a wide range of customizable widgets, such as buttons, labels, text boxes, check boxes, radio buttons, list boxes, and more. These widgets can be configured to suit your specific application requirements.

  • Easy to create complex layouts − Tkinter provides several geometry managers (pack, grid, and place) that help in arranging widgets on the screen in a flexible manner.

  • High-level of control over user interfaces − Tkinter provides a high level of control over the look and feel of the user interface, allowing you to customize the appearance of widgets, fonts, colors, and more.

  • Support for event-driven programming − Tkinter is based on an event-driven programming model, which means that it is designed to respond to user events, such as mouse clicks, button presses, and keyboard input. This makes it easy to create interactive applications.

Overall, Tkinter is a versatile and easy-to-use GUI toolkit that can help you create professional-looking desktop applications with minimal effort.

Prerequisites

Before we dive into the details of creating a GUI, you should have a basic understanding of programming, object-oriented programming (OOP) concepts, and how to work with the Tkinter module.

List of recommended settings

  • pip install tkinter

  • It is expected that the user will have access to any standalone IDE such as VS-Code, PyCharm, Atom or Sublime text.

  • Even online compilers can also be used such as Kaggle.com, Google Cloud platform or any other will do.

  • Updated version of. At the time of writing the article I have used 3.10.9 version.

  • Knowledge of the use of Jupyter notebook.

  • Knowledge and application of virtual environment would be beneficial but not required.

Creating GUI to Get Domain Information

Step 1: Import Necessary Libraries

The first step is to import the required libraries for creating the GUI application. The following libraries are required −

from tkinter import *
import whois
import socket

Here, we imported the `tkinter` library for creating the graphical user interface and the `whois` and `socket` libraries for getting domain-related information.

Step 2: Create a Window

Next, we create a window frame where all the widgets will be placed. The below code will create a window of size (500,400).

def __init__(self):
   self.window = Tk()
   self.window.geometry("500x400")
   self.window.title("Domain Information")

Step 3: Creating Labels and Text Boxes

After creating the window, we will create labels, textboxes, and buttons for getting the domain name from the user. The below code will create a label with the text "Enter Domain Name" and a textbox for getting the domain name from the user.

class DomainInfoGUI:
   def __init__(self):
      self.window = Tk()
      self.window.geometry("500x400")
      self.window.title("Domain Information")

      self.lbl_domain = Label(self.window, text="Enter Domain Name")
      self.lbl_domain.pack(pady=10)

      self.entry_domain = Entry(self.window, width=30)
      self.entry_domain.pack(pady=5)

      self.lbl_whois = None
      self.txt_whois = None
      self.lbl_dns = None
      self.txt_dns = None

      self.btn_whois = Button(self.window, text="Get WHOIS Information", command=self.get_whois_info)
      self.btn_whois.pack(pady=10)

      self.btn_dns = Button(self.window, text="Get DNS Information", command=self.get_dns_info)
      self.btn_dns.pack(pady=10)

      self.btn_clear = Button(self.window, text="Clear All", command=self.clear)
      self.btn_clear.pack(pady=10)

Step 4: WHOIS Information

Now, let's create a button that will get WHOIS information about the domain. The WHOIS information contains details like domain owner, registrar, server location, and much more.

def get_whois_info(self):
   domain_name = self.entry_domain.get()
   w = whois.whois(domain_name)
   self.lbl_whois = Label(self.window, text="WHOIS information of "+ domain_name +": ")
   self.lbl_whois.pack(pady=10)
   self.txt_whois = Text(self.window, height=15, width=70)
   self.txt_whois.pack(pady=5)
   self.txt_whois.insert(END, str(w))

Step 5: DNS Lookup

Next, we will create a button that will perform a DNS lookup of the domain. The DNS lookup returns the IP address of the domain server.

def get_dns_info(self):
   domain_name = self.entry_domain.get()
   ip_address = socket.gethostbyname(domain_name)
   self.lbl_dns = Label(self.window, text="DNS lookup result of "+ domain_name +": ")
   self.lbl_dns.pack(pady=10)
   self.txt_dns = Text(self.window, height=1, width=30)
   self.txt_dns.pack(pady=5)
   self.txt_dns.insert(END, ip_address)

Step 6: Clear Button

Finally, we will create a button that will clear all the labels, textboxes, and buttons.

def clear(self):
   if self.lbl_whois:
      self.lbl_whois.destroy()
   if self.txt_whois:
      self.txt_whois.destroy()
   if self.lbl_dns:
      self.lbl_dns.destroy()
   if self.txt_dns:
      self.txt_dns.destroy()
gui = DomainInfoGUI()
gui.window.mainloop()

Final code, program

from tkinter import *
import whois
import socket

class DomainInfoGUI:
   def __init__(self):
      self.window = Tk()
      self.window.geometry("500x400")
      self.window.title("Domain Information")

      self.lbl_domain = Label(self.window, text="Enter Domain Name")
      self.lbl_domain.pack(pady=10)

      self.entry_domain = Entry(self.window, width=30)
      self.entry_domain.pack(pady=5)

      self.lbl_whois = None
      self.txt_whois = None
      self.lbl_dns = None
      self.txt_dns = None

      self.btn_whois = Button(self.window, text="Get WHOIS Information", command=self.get_whois_info)
      self.btn_whois.pack(pady=10)

      self.btn_dns = Button(self.window, text="Get DNS Information", command=self.get_dns_info)
      self.btn_dns.pack(pady=10)

      self.btn_clear = Button(self.window, text="Clear All", command=self.clear)
      self.btn_clear.pack(pady=10)

   def get_whois_info(self):
      domain_name = self.entry_domain.get()
      w = whois.whois(domain_name)
      self.lbl_whois = Label(self.window, text="WHOIS information of "+ domain_name +": ")
      self.lbl_whois.pack(pady=10)
      self.txt_whois = Text(self.window, height=15, width=70)
      self.txt_whois.pack(pady=5)
      self.txt_whois.insert(END, str(w))

   def get_dns_info(self):
      domain_name = self.entry_domain.get()
      ip_address = socket.gethostbyname(domain_name)
      self.lbl_dns = Label(self.window, text="DNS lookup result of "+ domain_name +": ")
      self.lbl_dns.pack(pady=10)
      self.txt_dns = Text(self.window, height=1, width=30)
      self.txt_dns.pack(pady=5)
      self.txt_dns.insert(END, ip_address)

   def clear(self):
      if self.lbl_whois:
         self.lbl_whois.destroy()
      if self.txt_whois:
         self.txt_whois.destroy()
      if self.lbl_dns:
         self.lbl_dns.destroy()
      if self.txt_dns:
         self.txt_dns.destroy()

gui = DomainInfoGUI()
gui.window.mainloop()

The program creates three buttons - "Get WHOIS Information", "Get DNS Information", and "Clear All". When the "Get WHOIS Information" button is clicked, it calls the get_whois_info() function. Similarly, when the "Get DNS Information" button is clicked, it calls the get_dns_info() function. Finally, when the "Clear All" button is clicked, it calls the clear() function.

Output

Step 2: After the user inputs the query we can see the result

This picture shows user input and output of the domain availability checker.

Conclusion

In this instruction manual, we created a GUI application using Tkinter library in python to get domain information. We used WHOIS and DNS lookups to get the domain owner, registrar, server location, and IP address of the domain. With this, end-users can easily get domain-related information without having technical knowledge.

Updated on: 20-Apr-2023

225 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements