Check connectivity of 5000 + servers from ansible and get list of hosts which are connectable and which are not
Maybe a simple shell script would be more useful. If must to use ansible, it could be something like that (assuming you have all servers in group testall):

- hosts: testall
  connection: local
  gather_facts: false
  tasks:

    - wait_for:
        timeout: 2
        port: 43
        host: '{{ (ansible_ssh_host|default(ansible_host))|default(inventory_hostname) }}'
      register: waitfor
      ignore_errors: true

    - copy:
        content: |
          {% for host in groups['testall'] %}
          {% if hostvars[host].waitfor.failed %}{{ hostvars[host].inventory_hostname }} {% endif %}
          {% endfor %}
        dest: /tmp/bad_file
      delegate_to: localhost

    - copy:
        content: |
          {% for host in groups['testall'] %}
          {% if not hostvars[host].waitfor.failed %}{{ hostvars[host].inventory_hostname }} {% endif %}
          {% endfor %}
        dest: /tmp/good_file
      delegate_to: localhost



hosts that have this port opened will be in /tmp/good_file, others are in /tmp/bad_file