๐ PTRex ๐ฆ Reverse DNS Lookup Script
This Bash script performs reverse DNS (PTR) lookups on a given IP, CIDR range, or a list of IPs from a file. It efficiently resolves hostnames using getent hosts
, tracks progress, and runs queries in parallel for speed.
๐ Features
โ
Accepts a single IP, CIDR range, or file with multiple IPs
โ
Uses getent hosts
for reverse DNS (PTR) lookups ๐
โ
Parallel execution (up to 50 requests at a time) for faster results โก
โ
Tracks progress dynamically ๐
โ
Filters and outputs only successful PTR lookups (hostnames only) ๐
๐ Installation
Ensure you have prips
git
installed for CIDR expansion:
bash
sudo apt install prips git
git clone https://github.com/povzayd/ptrex.git
cd ptrex && chmod +x *
./ptrex
๐ Usage Run the script and enter an IP, CIDR range, or a file path when prompted:
bash
./ptrex
๐ Global Package
Making this shell script global will alow you to execute this in any directory
For that just move the file ptrex
to bin
or sbin
bash
mv ptrex /usr/bin
or
mv ptrex /usr/sbin
๐ Example Inputs
1๏ธโฃ Single IP: 8.8.8.8
2๏ธโฃ CIDR Range: 192.168.1.0/24
3๏ธโฃ File with IPs: /path/to/ips.txt
๐ Output Example
[+] Processing IPs from file: ips.txt
[+] Requests made: 12 / 100
[+] Completed!
โ
-> example.com
โ
-> mail.google.com
โ
-> somehost.net
๐ How It Works 1๏ธโฃ User Input
- Prompts user to enter an IP, CIDR, or file path
- Determines input type (single IP, CIDR, or file)
2๏ธโฃ IP Expansion (if CIDR)
- Uses
prips
to generate a list of IPs from the CIDR range
3๏ธโฃ Parallel Reverse DNS Lookups
- Uses
getent hosts
to fetch PTR records ๐ต๏ธ - Runs up to 50 parallel lookups using
xargs -P 50
- Displays live progress updates
4๏ธโฃ Output Processing
- Saves only successful hostname lookups ๐ฏ
- Hides IPs, displaying hostnames only
5๏ธโฃ Cleanup
- Deletes temporary files after execution ๐งน
prips
is missing, CIDR expansion will fail
๐ฎ Future Improvements โจ Add logging for debugging โจ Implement timeouts for slow DNS responses โจ Support custom concurrency levels
This script is great for security assessments, network mapping, and passive reconnaissance when identifying hostnames associated with an IP range. ๐
*PLEASE NOTE THAT THE SCRIPT GIVES OUTPUT IN THE FORM OF
-> some.pointer.record.abc.com
IF YOU WANT TO REMOVE IT FROM YOUR TXT FILE JUST USE THE COMMAND
sed -i 's/->//g' file.txt
THIS WILL REMOVE ->
FROM EACH & EVERY LINE OF YOUR FILE.