Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
622 B
0
Indexable
Never
#!/bin/bash

# Check if the CSV file path is provided as an argument
if [ "$#" -ne 1 ]; then
    echo "Usage: $0 path/to/ips.csv"
    exit 1
fi

# Path to the CSV file containing IP addresses (passed as a parameter)
csv_path="$1"

# Read the CSV file line by line
while IFS=, read -r ip_address; do
    # Skip the header line if present
    if [[ "$ip_address" != "IPAddress" ]]; then
        # Perform nslookup and extract the name
        hostname=$(nslookup "$ip_address" | awk -F'=' '/name =/ {print $2}' | tr -d ' ')
        echo "IP: $ip_address -> Hostname: $hostname"
    fi
done < "$csv_path"
Leave a Comment