<?php

header('Content-Type: text/plain; charset=utf-8');

$targets = [
    ['smtp-relay.gmail.com', 587],
    ['smtp-relay.gmail.com', 465],
    ['smtp.gmail.com', 587],
    ['smtp.gmail.com', 465],
];

foreach ($targets as [$host, $port]) {
    echo "====================================\n";
    echo "Host: {$host}:{$port}\n";

    $records = dns_get_record($host, DNS_A);

    if (empty($records)) {
        echo "No se encontraron registros IPv4 A.\n\n";
        continue;
    }

    foreach ($records as $record) {
        $ip = $record['ip'] ?? null;

        if (!$ip) {
            continue;
        }

        echo "Probando IPv4 {$ip}:{$port}\n";

        $errno = 0;
        $errstr = '';
        $fp = @fsockopen($ip, $port, $errno, $errstr, 10);

        if ($fp) {
            echo "OK conectado por IPv4\n";
            fclose($fp);
        } else {
            echo "ERROR {$errno}: {$errstr}\n";
        }
    }

    echo "\n";
}