Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

aksdevs/host-ip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Host IP Lookup Tool

A Python script to resolve hostnames and retrieve both IPv4 and IPv6 addresses.

Project Structure

host-ip/
├── src/
│   └── get_host_ip.py      # Main script
├── tests/
│   └── test_get_host_ip.py # Test cases
├── results/                 # Output JSON files
├── hostnames.txt           # Input file with hostnames
└── README.md

Features

  • Resolves hostnames to IP addresses using direct DNS queries (like nslookup)
  • Supports both IPv4 (A records) and IPv6 (AAAA records)
  • Returns FQDN (Fully Qualified Domain Name)
  • Outputs results in JSON format
  • Handles DNS lookup errors gracefully
  • Falls back to socket resolution if DNS query fails

Usage

python src/get_host_ip.py hostnames.txt

Input Format

Create a hostnames.txt file with one hostname per line:

google.com
localhost
github.com

Output Format

Results are saved as JSON in the results/ directory:

[
  {
    "hostname": "google.com",
    "fqdn": "google.com",
    "ipv4": ["142.250.185.46"],
    "ipv6": ["2607:f8b0:4004:c07::71"]
  }
]

Running Tests

Run the test suite:

python -m pytest tests/

Or using unittest:

python -m unittest tests/test_get_host_ip.py -v

Troubleshooting

If IPv6 addresses are not being captured:

  1. Test DNS resolution directly:
python src/test_dns.py <hostname>
  1. Compare with nslookup:
nslookup <hostname>
  1. Ensure dnspython is installed:
pip install -r requirements.txt

Requirements

  • Python 3.6+
  • dnspython (for direct DNS queries like nslookup)

Installation

  1. Clone the repository:
git clone https://github.com/atulksin/host-ip.git
cd host-ip
  1. Install dependencies:
pip install -r requirements.txt

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages