' WHOIS client simulation via TCP — domain lookup
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i  AS LONG
    LOCAL queryCount  AS LONG
    LOCAL domainName(10) AS STRING
    LOCAL whoisServer AS STRING
    LOCAL responseLen  AS LONG
    LOCAL statusCode  AS LONG
    LOCAL responseLines(20) AS STRING
    LOCAL numResponses  AS LONG
    LOCAL lineIdx  AS LONG
    PRINT "=== WHOIS Client ==="
    PRINT

    whoisServer = "whois.verisign-grs.com"
    queryCount = 3
    domainName(0) = "example.com                    "
    domainName(1) = "google.org                     "
    domainName(2) = "microsoft.net                  "

    PRINT "WHOIS Server: " & whoisServer
    PRINT "Port: 43"
    PRINT

    PRINT "--- Query: " & TRIM$(domainName(0)) & " ---"
    PRINT "  Sending query..."
    PRINT "  Response received."

    statusCode = 1
    numResponses = 5
    responseLines(0) = "Domain Name: EXAMPLE.COM                        "
    responseLines(1) = "Registry Domain ID: 123456789_DOMAIN_COM-VRSN   "
    responseLines(2) = "Creation Date: 1995-08-14T04:00:00Z             "
    responseLines(3) = "Registry Expiry Date: 2027-08-13T04:00:00Z     "
    responseLines(4) = "Name Server: NS1.EXAMPLE.COM                    "

    IF statusCode = 1 THEN
        FOR lineIdx = 0 TO numResponses - 1
            PRINT "  " & TRIM$(responseLines(lineIdx))
        NEXT lineIdx
    ELSE
        PRINT "  ERROR: Domain not found or query failed"
    END IF
    PRINT

    PRINT "--- Query: " & TRIM$(domainName(1)) & " ---"
    PRINT "  Sending query..."
    PRINT "  Response received."
    PRINT "  Domain Name: GOOGLE.ORG"
    PRINT "  Creation Date: 2000-01-15"
    PRINT "  Name Server: NS1.GOOGLE.COM"
    PRINT

    PRINT "--- Query: " & TRIM$(domainName(2)) & " ---"
    PRINT "  Sending query..."
    PRINT "  Response received."
    PRINT "  Domain Name: MICROSOFT.NET"
    PRINT "  Creation Date: 1995-05-02"
    PRINT "  Name Server: NS1.MICROSOFT.NET"
    PRINT

    PRINT "--- WHOIS Protocol ---"
    PRINT "  TCP connection to port 43"
    PRINT "  Send: <domain>\r\n"
    PRINT "  Receive: text response"
    PRINT "  Close connection"
    PRINT

    PRINT "--- Common WHOIS Servers ---"
    PRINT "  .com, .net: whois.verisign-grs.com (port 43)"
    PRINT "  .org: whois.pir.org (port 43)"
    PRINT "  .gov: whois.dotgov.gov (port 43)"
    PRINT "  .edu: whois.educause.edu (port 43)"
    PRINT "  .us: whois.nic.us (port 43)"
    PRINT

    PRINT "--- DECLARE Signature (TCP) ---"
    PRINT "  Uses Winsock 2.0 (WS2_32.DLL)"
    PRINT "  socket(), connect(), send(), recv(), closesocket()"

    PRINT
    PRINT "WHOIS client simulation complete."

    FUNCTION = 0
END FUNCTION
