testinfra/modules/socket.py
def is_listening(self):
        """Test if socket is listening

        >>> Socket("unix:///var/run/docker.sock").is_listening
        False
        >>> # This HTTP server listen on all ipv4 adresses but not on ipv6
        >>> Socket("tcp://0.0.0.0:80").is_listening
        True
        >>> Socket("tcp://:::80").is_listening
        False
        >>> Socket("tcp://80").is_listening
        False

        .. note:: If you don't specify a host for udp and tcp sockets,
                  then the socket is listening if and only if the
                  socket listen on **both** all ipv4 and ipv6 addresses
                  (ie 0.0.0.0 and ::)
        """
        sockets = self.get_sockets(True)
        if self.protocol == "unix":
            return ("unix", self.host) in sockets
        else:
            allipv4 = (self.protocol, "0.0.0.0", self.port) in sockets
            allipv6 = (self.protocol, "::", self.port) in sockets
            return (
                all([allipv4, allipv6])
                or (
                    self.host is not None
                    and (
                        (":" in self.host and allipv6 in sockets)
                        or (":" not in self.host and allipv4 in sockets)
                        or (self.protocol, self.host, self.port) in sockets)
                    )
            )
Test if socket is listening

        >>> Socket("unix:///var/run/docker.sock").is_listening
        False
        >>> # This HTTP server listen on all ipv4 adresses but not on ipv6
        >>> Socket("tcp://0.0.0.0:80").is_listening
        True
        >>> Socket("tcp://:::80").is_listening
        False
        >>> Socket("tcp://80").is_listening
        False

        .. note:: If you don't specify a host for udp and tcp sockets,
                  then the socket is listening if and only if the
                  socket listen on **both** all ipv4 and ipv6 addresses
                  (ie 0.0.0.0 and ::)
        


: If you don't specify a host for udp and tcp sockets,
then the socket is listening if and only if the
socket listen on **both** all ipv4 and ipv6 addresses
: If you don ' t specify a host for udp and tcp sockets then the socket is listening if and only if the socket listen on ** both ** all ipv4 and ipv6 addresses
def is_listening(self):
        sockets = self.get_sockets(True)
        if self.protocol == "unix":
            return ("unix", self.host) in sockets
        else:
            allipv4 = (self.protocol, "0.0.0.0", self.port) in sockets
            allipv6 = (self.protocol, "::", self.port) in sockets
            return (
                all([allipv4, allipv6])
                or (
                    self.host is not None
                    and (
                        (":" in self.host and allipv6 in sockets)
                        or (":" not in self.host and allipv4 in sockets)
                        or (self.protocol, self.host, self.port) in sockets)
                    )
            )
def is_listening ( self ) : sockets = self . get_sockets ( True ) if self . protocol == "unix" : return ( "unix" , self . host ) in sockets else : allipv4 = ( self . protocol , "0.0.0.0" , self . port ) in sockets allipv6 = ( self . protocol , "::" , self . port ) in sockets return ( all ( [ allipv4 , allipv6 ] ) or ( self . host is not None and ( ( ":" in self . host and allipv6 in sockets ) or ( ":" not in self . host and allipv4 in sockets ) or ( self . protocol , self . host , self . port ) in sockets ) ) )
Test if socket is listening
>>> Socket("unix:///var/run/docker.sock").is_listening
False
>>> # This HTTP server listen on all ipv4 adresses but not on ipv6
>>> Socket("tcp://0.0.0.0:80").is_listening
True
>>> Socket("tcp://:::80").is_listening
False
>>> Socket("tcp://80").is_listening
False
Test if socket is listening >>> Socket ( " unix : /// var / run / docker . sock " ) . is_listening False >>> # This HTTP server listen on all ipv4 adresses but not on ipv6 >>> Socket ( " tcp : // 0 . 0 . 0 . 0 : 80 " ) . is_listening True >>> Socket ( " tcp : // ::: 80 " ) . is_listening False >>> Socket ( " tcp : // 80 " ) . is_listening False
"""Test if socket is listening

        >>> Socket("unix:///var/run/docker.sock").is_listening
        False
        >>> # This HTTP server listen on all ipv4 adresses but not on ipv6
        >>> Socket("tcp://0.0.0.0:80").is_listening
        True
        >>> Socket("tcp://:::80").is_listening
        False
        >>> Socket("tcp://80").is_listening
        False

        .. note:: If you don't specify a host for udp and tcp sockets,
                  then the socket is listening if and only if the
                  socket listen on **both** all ipv4 and ipv6 addresses
                  (ie 0.0.0.0 and ::)
        """
self