77 lines
1.7 KiB
Markdown
77 lines
1.7 KiB
Markdown
# getIps.sh
|
|
|
|
A bash script that resolves hostnames to their IPv4 and IPv6 addresses using DNS lookups.
|
|
|
|
## Description
|
|
|
|
This script reads a list of hostnames from an input file and performs DNS lookups to find their corresponding IPv4 and IPv6 addresses. The results are written to an output file in a tab-separated format.
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
./getIps.sh <input_file> <output_file>
|
|
```
|
|
|
|
### Arguments
|
|
|
|
- `input_file`: Path to a text file containing hostnames (one per line)
|
|
- `output_file`: Path where the results will be written
|
|
|
|
### Example
|
|
|
|
```bash
|
|
./getIps.sh hosts.txt results.txt
|
|
```
|
|
|
|
## Input Format
|
|
|
|
The input file should contain hostnames, one per line:
|
|
|
|
```
|
|
google.com
|
|
github.com
|
|
stackoverflow.com
|
|
```
|
|
|
|
## Output Format
|
|
|
|
The output file will contain tab-separated values with the following columns:
|
|
|
|
```
|
|
hostname IPv4_address IPv6_address
|
|
```
|
|
|
|
Example output:
|
|
```
|
|
google.com 142.250.191.14 2a00:1450:4001:80e::200e
|
|
github.com 140.82.112.4 N/A
|
|
stackoverflow.com 151.101.1.69 N/A
|
|
```
|
|
|
|
## Features
|
|
|
|
- Resolves both IPv4 (A records) and IPv6 (AAAA records) addresses
|
|
- Handles empty lines in input file gracefully
|
|
- Shows "N/A" for addresses that cannot be resolved
|
|
- Clears previous output file before writing new results
|
|
- Provides usage information if incorrect arguments are provided
|
|
|
|
## Requirements
|
|
|
|
- `dig` command (part of dnsutils package)
|
|
- Bash shell
|
|
|
|
## Installation
|
|
|
|
Make the script executable:
|
|
|
|
```bash
|
|
chmod +x getIps.sh
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
- The script will exit with an error if the wrong number of arguments is provided
|
|
- Empty lines in the input file are automatically skipped
|
|
- DNS resolution failures are handled gracefully (shows "N/A")
|