Monday, April 21, 2025

Domain to IP Bulk Lookup Tool - Python

Content of bulk-domains.txt

google.com
bing.com
yahoo.com
facebook.com
import socket

file = open('bulk-domains.txt', 'r')

domain_list = []

for x in file.readlines():
    domain_list.append(x.rstrip())

for y in domain_list:
    print(y + ' -> ' + socket.gethostbyname(y))

Detailed explanation of the code:

  1. import socket - The socket module is imported to enable socket programming in Python.
  2. file = open('bulk-domains.txt', 'r') - This line of code opens a file named bulk-domains.txt in read mode and assigns it to the variable file.
  3. domain_list = [] - An empty list named domain_list is created to hold the domain names from the bulk-domains.txt file.
  4. for x in file.readlines(): - The readlines() method reads each line of the bulk-domains.txt file and returns a list of strings. The for loop iterates over each string in the list.
  5. domain_list.append(x.rstrip()) - The rstrip() method removes the newline character at the end of each string, and the resulting string is appended to the domain_list.
  6. for y in domain_list: - The for loop iterates over each item in the domain_list.
  7. socket.gethostbyname(y) - The gethostbyname() method takes a domain name as an argument and returns its corresponding IP address.
  8. print(y + ' -> ' + socket.gethostbyname(y)) - The domain name and its corresponding IP address are printed to the console with an arrow symbol between them.

This code reads a list of domain names from a file, obtains their IP addresses using the socket module, and prints the domain name and IP address pairs to the console.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...