No description
Find a file
2025-06-12 14:40:18 +02:00
getptr Handle CNAMEs to work with subdomains 2025-06-12 14:40:18 +02:00
LICENSE Initial commit 2025-06-11 00:09:56 +02:00
README.md Rotate the second arrow 2025-06-11 17:05:13 +02:00

getptr

A lightweight Bash utility to resolve a hostname to its IP address (preferring IPv6 by default), followed by a reverse DNS (PTR) lookup of that IP.


Features

  • Resolves hostnames to either IPv6 (AAAA) or IPv4 (A)
  • Performs a reverse DNS (PTR) lookup on the resolved IP
  • Supports:
    • -6 to force IPv6 only
    • -4 to force IPv4 only
    • Default mode prefers IPv6 and falls back to IPv4
  • Ideal for scripts and network diagnostics
  • Pure Bash, portable and dependency-light (uses dig)

Installation

Copy the script to your ~/.local/bin directory:

mkdir -p ~/.local/bin
cp getptr ~/.local/bin/
chmod +x ~/.local/bin/getptr

Usage

getptr [options] <hostname>

Options

Flag Description
-6 Use IPv6 (AAAA record only)
-4 Use IPv4 (A record only)
none Prefer IPv6, fallback to IPv4

Examples

getptr interlunium.nl
getptr -6 superworstenbroodje.nl
getptr -4 opperkneus.nl

Example output

$ getptr appdwang.nl
appdwang.nl -> 2a01:7c8:d007:3ae::1 <- jenny.interlunium.nl.

$ getptr -6 almende.com
almende.com -> 2a01:7c8:aac7:11f::1 <- elise.almende.org.

$ getptr -4 bad.solutions
bad.solutions -> 192.64.119.217 <- [no PTR record]

Requirements

  • Bash
  • dig (usually part of bind-utils or dnsutils)

License

This project is licensed under the GNU General Public License v3.0 (GPLv3). You are free to use, modify, and redistribute it under the terms of the GPLv3.

For details, see: https://www.gnu.org/licenses/gpl-3.0.en.html