WebTools

307 Useful Tools & Utilities to make life easier.

Domain WHOIS

Get WHOIS Information about a domain name.

Understanding the Domain WHOIS Tool Mechanism

The Domain WHOIS Lookup tool operates by establishing a direct TCP connection to the appropriate authoritative WHOIS server for a given domain name. Unlike web-based APIs that cache results, this tool queries the registry databases in real-time using the PHP fsockopen function over port 43. The system maps over 120 Top-Level Domains (TLDs) to their respective WHOIS servers and executes low-level socket communication to retrieve raw domain registration records directly from the source.

Input Parsing and Regex Validation

When you submit a domain, the tool first passes the input through a filter_url() sanitization routine to strip out unnecessary protocol prefixes like http://, https://, and trailing paths. The sanitized string is then evaluated against a strict regular expression: /^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/.

This regex enforces several standard domain rules:

  • The domain must begin and end with an alphanumeric character (no leading or trailing hyphens).
  • The main domain segment must be between 1 and 61 characters long (ensuring the maximum total length stays within RFC limits).
  • It must contain a dot followed by a TLD consisting of at least two alphabetic characters.

If the input fails this pattern, the system immediately halts and throws an invalid domain format error.

TLD Resolution and Server Mapping

After validation, the tool uses internal get_domain() and get_tld() functions to isolate the exact Top-Level Domain (e.g., extracting com from example.com). The system maintains an extensive, hardcoded dictionary mapping TLDs to their authoritative registries. This dictionary includes:

  • Generic TLDs (gTLDs): Maps domains like .com and .net to whois.verisign-grs.com, and .org to whois.publicinterestregistry.org.
  • Country-Code TLDs (ccTLDs): Routes requests for .uk to whois.nic.uk, .ca to whois.cira.ca, and .jp to whois.jprs.jp.
  • Specialized and Brand TLDs: Handles queries for domains like .gov (routed to whois.dotgov.gov), .edu, .museum, as well as brand TLDs like .google and .apple.

Additionally, the tool hooks into the application's DomainWhoisSettings. This allows system administrators to dynamically inject custom WHOIS server mappings or override the default routing logic for specific TLDs. If the parsed TLD does not exist in the combined server array, the tool triggers an "unsupported TLD" error.

Socket Communication and Data Retrieval

Once the correct WHOIS server is identified, the backend attempts to open a socket connection using fsockopen targeting port 43. The system enforces a strict 10-second timeout to prevent the application from hanging on unresponsive servers. The tool applies stream_set_timeout to the active socket stream.

If the connection succeeds, the server receives the requested domain string appended with a carriage return and line feed (\r\n). The tool enters a while(!feof($afp)) loop, reading the incoming byte stream line-by-line using fgets() until the end-of-file marker is reached. The socket is then safely closed, and the raw text output is rendered into the frontend's results textarea.

A Concrete Worked Example

Let's examine how the tool processes the input https://www.github.io/:

  1. Sanitization: The filter_url() function strips https://www. and the trailing slash, resulting in github.io.
  2. Validation: The string github.io successfully matches the regex pattern.
  3. Extraction: The domain is split, identifying io as the TLD.
  4. Server Lookup: The system looks up io in the dictionary and matches it to whois.nic.io.
  5. Socket Execution: A TCP connection is opened to whois.nic.io on port 43 with a 10-second timeout. The string github.io\r\n is written to the socket.
  6. Output: The registry responds with the raw text payload containing the registrar information, creation date, and nameservers, which is then populated into the user interface.

Frequently Asked Questions

Why does the tool return a "Service Unavailable" error?
The tool requires the PHP fsockopen function to establish outgoing TCP connections. If the server hosting the application has disabled this function for security reasons, the component immediately triggers an ERROR_SERVICE_UNAVAILABLE state during its initialization phase.
How does the tool handle unresponsive WHOIS servers?
The system implements a hard 10-second timeout for the socket connection. If the target WHOIS server (e.g., whois.verisign-grs.com) fails to respond or complete the data transfer within 10 seconds, the fsockopen or stream timeout triggers, safely aborting the operation and returning an ERROR_CONNECTION_FAILED message to the user.
What happens if I try to look up a domain with a rare or new TLD?
The tool verifies the TLD against its internal dictionary and any custom servers added via DomainWhoisSettings. If the TLD is missing from these arrays, the tool intentionally aborts and displays an "unsupported TLD" message rather than guessing a generic WHOIS server, as guessing would result in a guaranteed socket failure.
Does the regex validation allow internationalized domain names (IDNs)?
The primary regex pattern (/^[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}$/) specifically enforces ASCII alphanumeric characters and hyphens. Standard Unicode characters are not directly matched, meaning IDNs must be provided in their Punycode format (e.g., starting with xn--) to pass the validation step.

Contact

Missing something?

Feel free to request missing tools or give some feedback using our contact form.

Contact Us