community.windows.win_listen_ports_facts (2.2.0) — module

Recopilates the facts of the listening ports of the machine

| "added in version" 1.10.0 of community.windows"

Authors: David Nieto (@david-ns)

Install collection

Install with ansible-galaxy collection install community.windows:==2.2.0


Add to requirements.yml

  collections:
    - name: community.windows
      version: 2.2.0

Description

Recopilates the information of the TCP and UDP ports of the machine and the related processes.

State of the TCP ports could be filtered, as well as the format of the date when the parent process was launched.

The module's goal is to replicate the functionality of the linux module listen_ports_facts, mantaining the format of the said module.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Recopilate ports facts
  community.windows.win_listen_ports_facts:
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Retrieve only ports with Closing and Established states
  community.windows.win_listen_ports_facts:
    tcp_filter:
        - Closing
        - Established
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- name: Get ports facts with only the year within the date field
  community.windows.win_listen_ports_facts:
    date_format: '%Y'

Inputs

    
tcp_filter:
    default:
    - Listen
    description:
    - Filter for the state of the TCP ports that will be recopilated.
    - Supports multiple states (Bound, Closed, CloseWait, Closing, DeleteTCB, Established,
      FinWait1, FinWait2, LastAck, Listen, SynReceived, SynSent and TimeWait), that can
      be used alone or combined. Note that the Bound state is only available on PowerShell
      version 4.0 or later.
    elements: str
    type: list

date_format:
    default: '%c'
    description:
    - The format of the date when the process that owns the port started.
    - The date specification is UFormat
    type: str

Outputs

tcp_listen:
  description: List of dicts with the detected TCP ports
  elements: dict
  returned: success
  sample:
  - address: 127.0.0.1
    name: python
    pid: 5332
    port: 82
    protocol: tcp
    stime: Thu Nov 18 15:27:42 2021
    user: SERVER\Administrator
  type: list
udp_listen:
  description: List of dicts with the detected UDP ports
  elements: dict
  returned: success
  sample:
  - address: 127.0.0.1
    name: python
    pid: 5332
    port: 82
    protocol: udp
    stime: Thu Nov 18 15:27:42 2021
    user: SERVER\Administrator
  type: list

See also