-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_ptr.sh
32 lines (24 loc) · 859 Bytes
/
get_ptr.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# Check if domain name is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 domain-name"
exit 1
fi
# Get the domain name from the command line argument
domain_name=$1
# Use the host command to get the IP address of the domain
ip_address=$(host "$domain_name" | grep -oE "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | head -n 1)
# Check if the IP address was found
if [ -z "$ip_address" ]; then
echo "Could not resolve IP address for domain: $domain_name"
exit 1
fi
# Use the host command to get the PTR record of the IP address
ptr_record=$(host "$ip_address" | grep "domain name pointer" | awk '{print $5}')
# Check if the PTR record was found
if [ -z "$ptr_record" ]; then
echo "No PTR record found for IP address: $ip_address"
exit 1
fi
# Output the PTR record
echo "PTR Record for $ip_address: $ptr_record"