
ÖRNEK BİR UYGULAMA :
Bu betik için 2-3 gündür uğraşıyordum.6.deneme'de başarılı oldum.(zaten v6 ifadesinden anlarsınız.) Basit bir betik tasarlamıştım ama beni baya bir uğraştırdı kör olası...
Neyse....
KOD İÇERİĞİ : ( whois-query_v6.sh )
Kod: Tümünü seç
#!/usr/bin/env bash
# whois-query_v6.sh
# Queries WHOIS data for a given domain.
# Output layout:
# - Standard English WHOIS fields (top section)
# - **** separator
# - All Turkish interpretations collected together (bottom section)
#
# Fixes vs v5:
# - Anchored grep pattern (^Field:) prevents false matches such as
# "Registrar IANA ID" or "Registrar Abuse Contact" being caught.
# - Duplicate label+value pairs are suppressed (whois returns two blocks).
# - Name Server entries are deduplicated but all unique values are shown.
#
# Subdomain stripping: forum.sordum.net -> sordum.net (automatic)
# Known limitation: ccSLDs such as co.uk, com.tr, net.au are not handled.
# Usage: whois-query_v6.sh [domain-or-url]
set -euo pipefail
# ---------------------------------------------------------------------------
# UTF-8 locale: enables proper Turkish character rendering (ş ğ ü ö ç ı).
# The script file must also be saved as UTF-8.
# ---------------------------------------------------------------------------
export LANG=tr_TR.UTF-8
export LC_ALL=tr_TR.UTF-8
# ---------------------------------------------------------------------------
# Constants
# ---------------------------------------------------------------------------
readonly SEP_THIN="------------------------------------------------------------"
readonly SEP_THICK="************************************************************"
# Anchored pattern: line must START with the field name followed by a colon.
# This prevents "Registrar IANA ID", "Registrar Abuse Contact", etc. from matching.
# Both "Registry Expiry Date" (IANA block) and
# "Registrar Registration Expiration Date" (registrar block) are included.
readonly FIELD_PATTERN='^(Registrar|Creation Date|Registry Expiry Date|Registrar Registration Expiration Date|Updated Date|Name Server):'
# ---------------------------------------------------------------------------
# Build a Turkish interpretation string for a recognised WHOIS field.
# Arguments:
# $1 Field label (exact, e.g. "Registrar")
# $2 Field value
# ---------------------------------------------------------------------------
build_interpretation() {
local label="$1"
local value="$2"
local lc
lc="${label,,}"
case "$lc" in
registrar)
printf 'Kayıt Kuruluşu : "%s" kuruluşu tarafından kayıt altına alınmıştır.\n' "$value"
;;
"creation date")
printf 'Kayıt Tarihi : Alan adı ilk kez %s tarihinde oluşturulmuştur.\n' "$value"
;;
"registry expiry date"|"registrar registration expiration date")
printf 'Son Kullanma Tarihi : Alan adının geçerlilik süresi %s tarihinde dolacaktır.\n' "$value"
;;
"updated date")
printf 'Son Güncelleme : Kayıt bilgileri en son %s tarihinde güncellenmiştir.\n' "$value"
;;
"name server")
printf 'DNS Sunucusu : DNS sorguları "%s" isim sunucusuna yönlendirilmektedir.\n' "$value"
;;
esac
}
# ---------------------------------------------------------------------------
# Read input: prefer command-line argument, otherwise prompt.
# ---------------------------------------------------------------------------
if [[ -n "${1:-}" ]]; then
input="$1"
else
read -r -p "Enter a web address (e.g. https://www.example.com or example.com): " input
fi
# ---------------------------------------------------------------------------
# Extract bare domain: strip scheme, userinfo, path, port; lowercase.
# ---------------------------------------------------------------------------
domain="${input#*://}"
domain="${domain#*@}"
domain="${domain%%/*}"
domain="${domain%%:*}"
domain="${domain,,}"
# ---------------------------------------------------------------------------
# Strip subdomains: keep only the registrable root (last two labels).
# Example: forum.sordum.net -> sordum.net | www.google.com -> google.com
# ---------------------------------------------------------------------------
domain=$(printf '%s' "$domain" | awk -F'.' '{
if (NF > 2) print $(NF-1)"."$NF
else print $0
}')
if [[ -z "${domain// /}" ]]; then
printf 'Error: no valid domain was provided.\n' >&2
exit 1
fi
# ---------------------------------------------------------------------------
# Run WHOIS query.
# ---------------------------------------------------------------------------
printf 'Querying: %s\n' "$domain"
printf '%s\n' "$SEP_THIN"
whois_output=$(whois "$domain" 2>/dev/null) || {
printf 'Error: WHOIS query failed for "%s".\n' "$domain" >&2
exit 2
}
# Apply anchored grep filter.
matched_lines=$(printf '%s\n' "$whois_output" | grep -i -E "$FIELD_PATTERN" || true)
if [[ -z "$matched_lines" ]]; then
printf 'No relevant WHOIS fields were found for "%s".\n' "$domain" >&2
exit 2
fi
# ---------------------------------------------------------------------------
# Parse, deduplicate, and collect output.
# Associative array tracks "label|value" pairs already printed.
# ---------------------------------------------------------------------------
declare -A seen_pairs=()
match_count=0
turkish_block=""
while IFS= read -r line; do
raw_label="${line%%:*}"
raw_value="${line#*:}"
# Trim whitespace
label="${raw_label#"${raw_label%%[! ]*}"}"
label="${label%"${label##*[! ]}"}"
value="${raw_value#"${raw_value%%[! ]*}"}"
value="${value%"${value##*[! ]}"}"
[[ -z "$value" ]] && continue
# Build a deduplication key from label+value (case-insensitive value)
dedup_key="${label,,}|${value,,}"
# Skip if this exact label+value combination was already processed
if [[ -n "${seen_pairs[$dedup_key]:-}" ]]; then
continue
fi
seen_pairs["$dedup_key"]=1
# English output line
printf '%-38s %s\n' "${label}:" "$value"
# Collect Turkish interpretation
interp=$(build_interpretation "$label" "$value")
[[ -n "$interp" ]] && turkish_block+="${interp}"$'\n'
(( match_count++ )) || true
done <<< "$matched_lines"
printf '%s\n' "$SEP_THIN"
printf 'Total fields displayed: %d\n' "$match_count"
# ---------------------------------------------------------------------------
# Second section: Turkish interpretations collected together.
# ---------------------------------------------------------------------------
printf '\n%s\n' "$SEP_THICK"
printf "TÜRKÇE ÇIKTI - Alan Adı'nın Özetsel Web Bilgisi : %s\n" "$domain"
printf '%s\n' "$SEP_THICK"
if [[ -n "$turkish_block" ]]; then
printf '%s' "$turkish_block"
else
printf 'Türkçe yorum üretilecek alan bulunamadı.\n'
fi
printf '%s\n' "$SEP_THICK"

GNU/Linux'ta betik kodlayanların baya bir işine yarayacaktır.
Web Adresi :
https://www.shellcheck.net/

