Skip to content

Commit 9706ae6

Browse files
authored
Merge pull request Python-World#184 from AdityaJ7/dns-record
Added script for DNS record
2 parents 28f7a0f + 941dc26 commit 9706ae6

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

projects/DNS Record/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## DNS Record
2+
3+
This script takes the website name as input and returns its dns records.
4+
5+
#Requirements to run this file:
6+
7+
External library called dnspython has been used here and it can be installed easily by using the following command:
8+
9+
pip install -r requirements.txt
10+
11+
#How to use this script?
12+
13+
1.Install the requirements.
14+
15+
2. Type the following command
16+
17+
python dns_record.py
18+
19+
3.It will ask for a website:
20+
21+
You can give any website name for example: google.com

projects/DNS Record/dns_record.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Simple program to fetch dns record of a given website
2+
3+
import json
4+
import dns.resolver
5+
6+
#Dictionary to store the dns record of a website
7+
dns_record = {}
8+
9+
#User defined website
10+
website = input("Enter the name of the website: ")
11+
12+
#Fetching the 'A' record of the website and storing it in the dictionary
13+
a_record = dns.resolver.resolve(website, 'A')
14+
for ipval in a_record:
15+
dns_record['A_Record_IP'] = ipval.to_text()
16+
17+
#List to store the mx records of a website
18+
mx_record_list = []
19+
20+
#Fetching the mx records and storing them in the dictionary
21+
mx_record = dns.resolver.resolve(website,'MX')
22+
for server in mx_record:
23+
mx_record_list.append(server)
24+
for i, element in enumerate(mx_record_list):
25+
dns_record['MX_Record', i+1] = element
26+
27+
#Displaying the record on the screen
28+
for key,value in dns_record.items():
29+
print(f"{key} = {value}")
30+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dnspython==2.0.0

0 commit comments

Comments
 (0)