Skip to content

Instantly share code, notes, and snippets.

@mjmaley
Last active September 12, 2025 04:59
Show Gist options
  • Select an option

  • Save mjmaley/4b2ad9b5ccce6d356ddc829380ba74b4 to your computer and use it in GitHub Desktop.

Select an option

Save mjmaley/4b2ad9b5ccce6d356ddc829380ba74b4 to your computer and use it in GitHub Desktop.
reverse dns of a range of IPs
#!/bin/bash
# Parallel reverse DNS enumeration with configurable IP range
# Usage: ./reverse_dns.sh <start_ip> <end_ip> [max_jobs]
usage() {
echo "Usage: $0 <start_ip> <end_ip> [max_jobs]"
echo "Example: $0 100.64.0.1 100.64.2.255 50"
echo "Example: $0 192.168.1.1 192.168.1.254"
echo "Default max_jobs: 25"
exit 1
}
# Check arguments
if [ $# -lt 2 ] || [ $# -gt 3 ]; then
usage
fi
START_IP="$1"
END_IP="$2"
MAX_JOBS="${3:-25}" # Default to 25 if not specified
# Function to convert IP to integer
ip_to_int() {
local ip="$1"
local a b c d
IFS=. read -r a b c d <<< "$ip"
echo $((a * 256**3 + b * 256**2 + c * 256 + d))
}
# Function to convert integer to IP
int_to_ip() {
local int="$1"
local a b c d
a=$((int / 256**3))
b=$(((int % 256**3) / 256**2))
c=$(((int % 256**2) / 256))
d=$((int % 256))
echo "$a.$b.$c.$d"
}
# Validate IP format
validate_ip() {
local ip="$1"
if [[ ! $ip =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
echo "Error: Invalid IP format: $ip"
exit 1
fi
}
# Validate inputs
validate_ip "$START_IP"
validate_ip "$END_IP"
START_INT=$(ip_to_int "$START_IP")
END_INT=$(ip_to_int "$END_IP")
if [ $START_INT -gt $END_INT ]; then
echo "Error: Start IP ($START_IP) is greater than end IP ($END_IP)"
exit 1
fi
TOTAL_IPS=$((END_INT - START_INT + 1))
FOUND_FILE="reverse_dns_found_${START_IP//./}_to_${END_IP//./}.txt"
echo "Starting parallel reverse DNS enumeration"
echo "Range: $START_IP to $END_IP"
echo "Total IPs: $TOTAL_IPS"
echo "Max parallel jobs: $MAX_JOBS"
echo "Started at: $(date)"
# Clear output file
> "$FOUND_FILE"
# Function to perform reverse lookup
reverse_lookup() {
local ip="$1"
local result
result=$(dig +short +time=2 +tries=1 -x "$ip" 2>/dev/null)
if [ -n "$result" ] && [ "$result" != ";; connection timed out; no servers could be reached" ]; then
echo "$ip -> $result"
fi
}
export -f reverse_lookup
# Generate IP range and process in parallel
{
for ((ip_int = START_INT; ip_int <= END_INT; ip_int++)); do
int_to_ip $ip_int
done
} | xargs -n 1 -P "$MAX_JOBS" -I {} bash -c 'reverse_lookup "{}"' | tee "$FOUND_FILE"
echo ""
echo "Enumeration completed at: $(date)"
echo "Results saved to: $FOUND_FILE"
echo "Found records: $(wc -l < "$FOUND_FILE")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment