Exemple #1
0
    def get_peer(self):
        addr, port = address_parser.get_ip(self.req),\
                                               address_parser.get_port(self.req)

        if address_parser.is_valid_ipv4(addr):
            return Address(type=Address.TCP4, host=addr, port=port)

        if address_parser.is_valid_ipv6(addr):
            return Address(type=Address.TCP6, host=addr, port=port)
Exemple #2
0
    def get_peer(self):
        addr, port = address_parser.get_ip(self.req),\
                                               address_parser.get_port(self.req)

        if address_parser.is_valid_ipv4(addr):
            return Address(type=Address.TCP4, host=addr, port=port)

        if address_parser.is_valid_ipv6(addr):
            return Address(type=Address.TCP6, host=addr, port=port)
Exemple #3
0
    def get_peer(self):
        peer = Address.from_twisted_address(self.req.transport.getPeer())
        addr = address_parser.get_ip(_Transformer(self.req))

        if addr is None:
            return peer

        if address_parser.is_valid_ipv4(addr):
            return Address(type=Address.TCP4, host=addr, port=0)

        if address_parser.is_valid_ipv6(addr):
            return Address(type=Address.TCP6, host=addr, port=0)
Exemple #4
0
    def get_peer(self):
        peer = Address.from_twisted_address(self.req.transport.getPeer())
        addr = address_parser.get_ip(_Transformer(self.req))

        if addr is None:
            return peer

        if address_parser.is_valid_ipv4(addr):
            return Address(type=Address.TCP4, host=addr, port=0)

        if address_parser.is_valid_ipv6(addr):
            return Address(type=Address.TCP6, host=addr, port=0)
    def get_peer(self) -> typing.Optional[Address]:
        if not self.req_env.transport:
            return None

        peer = self.req_env.transport.get_extra_info("peername")
        if not peer:
            return None
        host, port = peer

        if address_parser.is_valid_ipv4(host):
            return Address(type=Address.TCP4, host=host, port=port)

        if address_parser.is_valid_ipv6(host):
            return Address(type=Address.TCP6, host=host, port=port)

        return None