false, 'message' => 'Only POST method allowed' ]); exit; } // Read JSON body $input = json_decode(file_get_contents('php://input'), true); $domain = $input['domain'] ?? ''; // Domain validation function validateDomain(string $domain): bool { return (bool) preg_match( '/^(?!-)(?:[a-zA-Z0-9-]{1,63}\.)+[a-zA-Z]{2,}$/', $domain ); } if (!$domain || !validateDomain($domain)) { http_response_code(400); echo json_encode([ 'success' => false, 'message' => 'Invalid domain' ]); exit; } // Fetch NS records $records = dns_get_record($domain, DNS_NS); $nsRecords = []; if ($records !== false) { foreach ($records as $record) { if (!empty($record['target'])) { $nsRecords[] = $record['target']; } } } // Response if (empty($nsRecords)) { echo json_encode([ 'success' => false, 'domain' => $domain, 'message' => 'No NS records found', 'records' => [] ]); exit; } echo json_encode([ 'success' => true, 'domain' => $domain, 'records' => $nsRecords ]);