def get_port_stats(port):
    """
    Iterate over connections and count states for specified port
    :param port: port for which stats are collected
    :return: Counter with port states
    """
    cnts = defaultdict(int)
    for c in psutil.net_connections():
        c_port = c.laddr[1]
        if c_port != port:
            continue
        status = c.status.lower()
        cnts[status] += 1
    return cnts

    Iterate over connections and count states for specified port
    :param port: port for which stats are collected
    :return: Counter with port states
    
src/collectors/portstat/portstat.py