# Where to Find the DigitalPlat FreeDomain WHOIS Server Source Code

> Find the DigitalPlat FreeDomain WHOIS server source code in the DigitalPlatDev/FreeDomain repository. Access the main implementation within the whois.py file today.

- Repository: [DigitalPlat Foundation/FreeDomain](https://github.com/DigitalPlatDev/FreeDomain)
- Tags: how-to-guide
- Published: 2026-02-25

---

**The DigitalPlat FreeDomain WHOIS server source code is located in the `opensource/whois_server` directory of the DigitalPlatDev/FreeDomain repository, with the main implementation residing in [`whois.py`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/whois.py).**

The DigitalPlat FreeDomain project provides a lightweight, self-contained Python implementation of a RFC-compliant WHOIS server. This guide identifies the exact source files, explains the core architecture, and demonstrates how to run and extend the server for production use.

## Repository Location and File Structure

The WHOIS server implementation is isolated under the `opensource/whois_server` path within the DigitalPlatDev/FreeDomain repository. This separation keeps the networking logic distinct from the frontend registration interfaces.

Key files include:

- **[`whois.py`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/whois.py)** – The core server implementation that handles TCP socket creation, request parsing, and response generation.
- **[`readme.md`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/readme.md)** – Documentation outlining usage requirements and the critical reminder that the `get_whois` data retrieval function must be implemented by the deployer.

## Core Architecture of the WHOIS Server

The server follows a minimal, synchronous socket-server pattern designed for clarity and resilience.

### Server Bootstrap and Socket Binding

In [`whois.py`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/whois.py), the `main()` function initializes the service by binding a TCP socket to `0.0.0.0:43` (the standard WHOIS port). It logs startup status and enters a listening loop to accept incoming client connections.

### Connection Handling and Request Processing

For each incoming connection, the server executes the following sequence:

1. **Timeout Configuration** – Sets a 10-second socket timeout to prevent hanging connections.
2. **Data Reception** – Reads up to 1024 bytes from the socket and decodes the payload as UTF-8.
3. **Request Logging** – Records the decoded domain query for debugging purposes.
4. **Response Generation** – Invokes the `whois(decoded_data)` function, which internally calls the pluggable `get_whois` helper to retrieve domain records.
5. **Client Response** – Sends the resulting string back to the client over the TCP connection.

### Error Handling and Resilience

The implementation includes comprehensive exception handling for decoding errors, socket timeouts, and unexpected runtime exceptions. Errors are logged internally, and clients receive a generic "Internal server error" message when necessary.

To ensure high availability, the script’s `if __name__ == "__main__"` block wraps the `main()` call inside an infinite retry loop. If the server encounters a critical failure, it sleeps briefly before restarting, maintaining service continuity without manual intervention.

## Extending the Server with Custom Data Sources

The DigitalPlat FreeDomain WHOIS server is architected as a lightweight scaffold that abstracts data storage. The `get_whois(domain)` function is intentionally left unimplemented (or as a stub) in the source code.

To deploy this server in production, you must provide a concrete implementation of `get_whois` that returns a plain-text WHOIS response string. This design allows integration with:

- **Relational databases** (e.g., MySQL or PostgreSQL tables storing domain registration data).
- **In-memory caches** (e.g., Redis for high-performance lookups).
- **External APIs** (e.g., proxying requests to upstream registrars or regional internet registries).

Example implementation structure:

```python
def get_whois(domain: str) -> str:
    # Query your database or API here

    record = database.lookup(domain)
    if record:
        return f"Domain Name: {domain}\nRegistrar: {record.registrar}\n..."
    return "Domain not found"

```

## Running and Testing the WHOIS Server

### Starting the Server

After implementing the `get_whois` function, launch the daemon from the repository root:

```bash
python -m opensource.whois_server.whois

```

The process will bind to port 43 and log its ready state to the console.

### Testing with Netcat

Verify functionality using a standard netcat client:

```bash
echo "example.com" | nc localhost 43

```

The server should return the WHOIS record text generated by your `get_whois` implementation.

### Programmatic Query Example

For automated testing or integration, use a Python socket client:

```python
import socket

def query_whois(host: str, domain: str, timeout: int = 5) -> str:
    with socket.create_connection((host, 43), timeout=timeout) as sock:
        sock.sendall(f"{domain}\n".encode("utf-8"))
        return sock.recv(4096).decode("utf-8")

# Query the local server

response = query_whois("127.0.0.1", "testdomain.free")
print(response)

```

## Summary

- The **DigitalPlat FreeDomain WHOIS server** source code resides in [`opensource/whois_server/whois.py`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/opensource/whois_server/whois.py) within the DigitalPlatDev/FreeDomain repository.
- The server operates as a **TCP socket service on port 43**, handling UTF-8 encoded domain queries with a 10-second timeout.
- **Extensibility is built-in**: the `get_whois` function is a pluggable hook that developers must implement to connect the server to their preferred data backend.
- **Resilience features** include comprehensive error handling and an automatic restart loop that maintains service availability after critical failures.

## Frequently Asked Questions

### Where exactly is the WHOIS server code located in the repository?

The WHOIS server implementation is located in the `opensource/whois_server` directory. The primary logic is contained in [`whois.py`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/whois.py), while [`readme.md`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/readme.md) provides setup instructions. You can view these files directly in the DigitalPlatDev/FreeDomain repository under the `main` branch.

### What port does the DigitalPlat FreeDomain WHOIS server use?

The server binds to **port 43**, which is the standard port assigned by IANA for WHOIS services. In [`whois.py`](https://github.com/DigitalPlatDev/FreeDomain/blob/main/whois.py), the `main()` function explicitly creates a TCP socket listening on `0.0.0.0:43` to accept incoming domain queries from any network interface.

### How do I add my own domain database to the WHOIS server?

You must implement the `get_whois(domain)` function, which is currently a stub in the source code. This function should accept a domain string and return a plain-text WHOIS response. You can connect this function to any backend—such as MySQL, PostgreSQL, Redis, or an external API—to retrieve registration data dynamically.

### Is the WHOIS server resilient to crashes or network errors?

Yes, the implementation includes multiple resilience mechanisms. It features a 10-second socket timeout to prevent hanging connections, comprehensive `try/except` blocks to handle decoding and network errors, and an infinite retry loop in the main execution block that restarts the server automatically after critical failures, ensuring continuous availability.