Monday, April 21, 2025

Doman Bulk Lookup Tool - Python Multi FQDN

import socket, time

list_domains = ['google.com', 'facebook.com', 'bing.com']

file = open('fqdn-bulk-report.txt', 'a')

for x in list_domains:
    #print(socket.getfqdn(x))
    file.write(socket.getfqdn(x) + '\n')
    time.sleep(2)

file.close()

This Python code performs the following tasks:

  1. Imports the modules 'socket' and 'time' using the 'import' keyword.
  2. Defines a list called 'list_domains' containing three domain names: 'google.com', 'facebook.com', and 'bing.com'.
  3. Opens a file called 'fqdn-bulk-report.txt' in 'append' mode and assigns it to a variable called 'file'. This file will be used to store the Fully Qualified Domain Names (FQDNs) of the domains in 'list_domains'.
  4. Iterates over each element in the 'list_domains' using a 'for' loop, and performs the following tasks:
    • Calls the 'socket.getfqdn()' method on each element to retrieve its FQDN.
    • Writes the FQDN to the 'fqdn-bulk-report.txt' file using the 'file.write()' method.
    • Pauses the program for 2 seconds using the 'time.sleep()' method.
  5. Closes the 'fqdn-bulk-report.txt' file using the 'file.close()' method.

Let's go through the code line by line to understand it in greater detail:

import socket, time

This line imports the 'socket' and 'time' modules into the script. The 'socket' module provides a way to communicate over a network, while the 'time' module provides functions to work with time-related tasks.

list_domains = ['google.com', 'facebook.com', 'bing.com']

This line creates a list called 'list_domains' containing three strings representing domain names: 'google.com', 'facebook.com', and 'bing.com'.  

file = open('fqdn-bulk-report.txt', 'a')

This line creates a file object called 'file' using the 'open()' function. The first argument is the name of the file to open, and the second argument specifies the mode in which to open it. In this case, 'a' stands for 'append', which means that new data will be added to the end of the file, rather than overwriting it 

for x in list_domains:

This line begins a 'for' loop that iterates over each element in 'list_domains'. The loop variable 'x' is assigned to each element in turn.

file.write(socket.getfqdn(x) + '\n')

This line calls the 'socket.getfqdn()' method with the current value of 'x' as an argument. This method returns the Fully Qualified Domain Name (FQDN) of the domain name passed to it. The FQDN includes the hostname and the domain name, separated by periods. The resulting string is then written to the 'fqdn-bulk-report.txt' file using the 'file.write()' method. The '\n' character is added to the end of the string to ensure that each FQDN is written on a new line.

time.sleep(2)

This line pauses the program for 2 seconds using the 'time.sleep()' method. This is done to prevent overwhelming the servers being queried with too many requests in a short period of time.

file.close()

This line closes the 'fqdn-bulk-report.txt' file using the 'file.close()' method. This ensures that any data written to the file is saved and that the file is released from memory.

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 .  ...