Skip to content
/ ptrex Public

PTRex is a Bash script for performing reverse DNS (PTR) lookups on single IPs, CIDR ranges, or IP lists. It uses getent hosts, supports parallel execution for speed, and filters results to show only successful lookups.

Notifications You must be signed in to change notification settings

povzayd/ptrex

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” 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 ๐Ÿงน

โš ๏ธ Notes โšก Only successful lookups (resolved hostnames) are displayed โšก Parallel execution speeds up large queries โšก If 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.

About

PTRex is a Bash script for performing reverse DNS (PTR) lookups on single IPs, CIDR ranges, or IP lists. It uses getent hosts, supports parallel execution for speed, and filters results to show only successful lookups.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages