Skip to content
Related Articles

Related Articles

Create a GUI to find the IP for Domain names using Python
  • Last Updated : 29 Dec, 2020

Prerequisite: Python GUI – tkinter

In this article, we are going to see how to find IP from Domain Names and bind it with GUI Application using Python. We will use iplookup module for looking up IP from Domain Names. It is a small module which accepts a single domain as a string, or multiple domains as a list, and returns a list of associated IP.

Run this code into your terminal for installation.

pip install iplookup

Approach:

  • Import module
  • Create objects of iplookup
  • Pass the domain into iplookup obj
  • Now traverse the IP

Implementation:



Python3




# import module
from iplookup import iplookup
  
#create object of iplookup
ip = iplookup.iplookup
  
# Input by geek
# domain name
domain = "geeksforgeeks.org"
  
# pass the domain
# into iplookup obj
result = ip(domain)
  
# traverse the ip
print("Domain name : ",domain)
print("Ip : ",result)

Output:

Domain name :  geeksforgeeks.org
Ip :  ['34.218.62.116']

IP lookup from domain GUI Application with Tkinter: This Script implements the above Implementation into a GUI.

Python3




# import modules
from tkinter import *
from tkinter import messagebox
from iplookup import iplookup
  
  
def get_ip():
    try:
        ip = iplookup.iplookup
        result = ip(e.get())
        res.set(result)
  
    except:
        messagebox.showerror("showerror", "Something wrong")
  
  
# object of tkinter
# and background set for light grey
master = Tk()
master.configure(bg='light grey')
  
# Variable Classes in tkinter
res = StringVar()
  
# Creating label for each information
# name using widget Label
Label(master, text="Enter website name :",
      bg="light grey").grid(row=0, sticky=W)
Label(master, text="Result :", bg="light grey").grid(row=1, sticky=W)
  
  
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=res, bg="light grey").grid(
    row=1, column=1, sticky=W)
  
  
e = Entry(master)
e.grid(row=0, column=1)
  
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text="Show", command=get_ip)
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5)
  
mainloop()

Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

My Personal Notes arrow_drop_up
Recommended Articles
Page :