Skip to content

Commit 5c5d42d

Browse files
authored
Merge pull request #368 from Nibba2018/dns-lookup
Add DNS Lookup
2 parents c3ceadc + 998cda8 commit 5c5d42d

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Python/DNS-Lookup/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# DNS Lookup
2+
The Domain Name System is a hierarchical and decentralized naming system for computers, services, or other resources connected to the Internet or a private network. It associates various information with domain names assigned to each of the participating entities.
3+
4+
## Executing the Script
5+
* Run: `python lookup.py <website or IP address>`
6+
* for e.g `python lookup.py google.com`
7+
* or `python lookup.py 142.250.67.174`
8+
9+
## Output
10+
11+
![output](output.png)

Python/DNS-Lookup/lookup.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
import socket
3+
import ipaddress
4+
5+
if len(sys.argv) < 2:
6+
sys.exit("Please provide an IP address or a domain name.")
7+
8+
query = sys.argv[1]
9+
10+
try:
11+
ipaddress.ip_address(query)
12+
except:
13+
ipv4, ipv6 = map(lambda x: x[4][0], socket.getaddrinfo(query,22,type=socket.SOCK_STREAM))
14+
print("Domain Name:", query)
15+
print("IPV4:", ipv4)
16+
print("IPV6:", ipv6)
17+
print("Server Domain:", socket.gethostbyaddr(ipv4)[0])
18+
else:
19+
ip_info = socket.gethostbyaddr(query)
20+
print("Domain Name:", ip_info[0])
21+
print("IP:", query)

Python/DNS-Lookup/output.png

20.8 KB
Loading

0 commit comments

Comments
 (0)