import socket
file = open('bulk-domains.txt', 'r')
domain_list = []
for x in file.readlines():
domain_list.append(x.rstrip())
report = open('domains.txt', 'w')
for y in domain_list:
report.write("-" * 45 + '\n')
report.write(y + '\t->\t' + socket.gethostbyname(y) + '\n')
report.close()
This code opens a file called 'bulk-domains.txt' in read-only mode using the open()
function and assigns the file object to a variable called file
. Then, an empty list called domain_list
is created.
The for
loop iterates through each line in the file
object using the readlines()
method. rstrip()
method is used to remove any newline characters or whitespace from the end of each line, and the cleaned-up line is appended to the domain_list
using the append()
method.
import socket
file = open('bulk-domains.txt', 'r')
domain_list = []
for x in file.readlines():
domain_list.append(x.rstrip())
After the domain_list
has been populated with domain names, the code creates a new file called domains.txt
in write mode using the open()
function and assigns the file object to a variable called report
.
The next for
loop iterates through each domain name in the domain_list
, and for each domain name, it writes a separator line consisting of 45 dashes using string multiplication. It then writes the domain name followed by the IP address of that domain name obtained by using the socket.gethostbyname()
method, which performs a DNS lookup to resolve the domain name to its IP address.
report = open('domains.txt', 'w')
for y in domain_list:
report.write("-" * 45 + '\n')
report.write(y + '\t->\t' + socket.gethostbyname(y) + '\n')
Finally, the report
file is closed using the close()
method.
report.close()
This code is useful for performing bulk DNS lookups to obtain the IP addresses of a large number of domain names, and can be modified to suit various use cases.
No comments:
Post a Comment