Build a Python WHOIS and Domain Age Checker (Spot Shady Domains Fast)


One of the fastest phishing tells costs nothing to check: how old is the domain? A “bank” website on a domain registered three days ago is almost certainly a scam. Legitimate brands sit on domains that are years old. Today we will build a small Python tool that pulls WHOIS data — registration date, registrar and expiry — for any domain.

What Is WHOIS?

WHOIS is the public record for a domain: who registered it, when, through which registrar, and when it expires. It is not secret data — it is published by design — which makes it a perfect defensive input. Scammers cannot fake a domain’s age.

The Code

Install the library first:

pip install python-whois

Then save this as domaincheck.py:

import whois
from datetime import datetime, timezone

def check_domain(domain: str):
    try:
        w = whois.whois(domain)
    except Exception as e:
        print(f"Could not look up {domain}: {e}")
        return
    created = w.creation_date
    if isinstance(created, list):
        created = created[0]
    expires = w.expiration_date
    if isinstance(expires, list):
        expires = expires[0]
    age_days = None
    if created:
        if created.tzinfo is None:
            created = created.replace(tzinfo=timezone.utc)
        age_days = (datetime.now(timezone.utc) - created).days
    print(f"Domain:    {domain}")
    print(f"Registrar: {w.registrar}")
    print(f"Created:   {created}")
    print(f"Expires:   {expires}")
    if age_days is not None:
        print(f"Age:       {age_days} days")
        if age_days < 30:
            print("WARNING: Very new domain — treat with suspicion.")
        elif age_days < 180:
            print("CAUTION: Young domain — verify before trusting.")
        else:
            print("OK: Established domain age.")
    else:
        print("Age: unknown (creation date not published)")

if __name__ == "__main__":
    domain = input("Enter a domain (e.g. example.com): ").strip()
    check_domain(domain)

How to Use It Defensively

Run it before you trust a link:

python3 domaincheck.py

Then combine the result with common sense: a brand-new domain plus a login form asking for credentials, plus a link that arrived by SMS or email you did not expect, equals do-not-click. Domain age alone never proves a site is safe — old domains get compromised too — but a young age is one of the strongest single red flags in phishing detection.

Level Up

  • Batch mode: read domains from a text file and flag every domain under 30 days old.
  • Add DNS checks: resolve the domain and compare its hosting country with what you expect.
  • Feed it into your log analyzer: when a suspicious domain appears in your proxy or email logs, age-check it automatically.
  • Respect rate limits. WHOIS servers throttle aggressive queries. Space out bulk lookups and cache results.

A Note on Privacy

WHOIS lookups are public-record queries — you are reading published data, not hacking anything. Just do not use the tool to harvest personal contact details from records that still publish them, and never use it to target individuals. Defense means checking domains, not doxxing people. You just built a phishing triage tool in under 50 lines. Keep it in your toolkit next to the log analyzer and the breach checker — small defensive scripts compound into real security habits.

Comments

Popular Posts