python类getpeername()的实例源码

miniircd.py 文件源码 项目:luftwaffel 作者: exp-publishing 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__(self, server, socket):
        self.server = server
        self.socket = socket
        self.channels = {}  # irc_lower(Channel name) --> Channel
        self.nickname = None
        self.user = None
        self.realname = None
        (self.host, self.port) = socket.getpeername()
        self.__timestamp = time.time()
        self.__readbuffer = ""
        self.__writebuffer = ""
        self.__sent_ping = False
        if self.server.password:
            self.__handle_command = self.__pass_handler
        else:
            self.__handle_command = self.__registration_handler
ENIP.py 文件源码 项目:PyCIP 作者: cpchrispye 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def __init__(self, socket, proto):
        self.host = socket.getsockname()
        self.peer = socket.getpeername()
        self.protocall = proto
        self.recevied_time = time.time()
client.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def connectionSuccess(self):
        socket = self.sub.socket
        self.sub.state = "dead"
        del self.sub
        self.state = "connected"
        self.cancelTimeout()
        p = self.factory.buildProtocol(self.buildAddress(socket.getpeername()))
        self.transport = self.transport_class(socket, p, self)
        p.makeConnection(self.transport)
client.py 文件源码 项目:sslstrip-hsts-openwrt 作者: adde88 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def connectionSuccess(self):
        socket = self.sub.socket
        self.sub.state = "dead"
        del self.sub
        self.state = "connected"
        self.cancelTimeout()
        p = self.factory.buildProtocol(self.buildAddress(socket.getpeername()))
        self.transport = self.transport_class(socket, p, self)
        p.makeConnection(self.transport)
ClientInterface.py 文件源码 项目:vagus 作者: privacore 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def addresss2nicestring(address):
    #address is a (str,port) tuple from socket.recvfrom() or socket.getpeername()
    #output is something nice such as "192.0.2.7" or "2001:0db8:1::7"
    if address!=None:
        return address[0]
    else:
        return None
tcp_http_https.py 文件源码 项目:honeypot 作者: fabio-d 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def handle_tcp_http(socket, dstport):
    socket = TextChannel(socket)

    try:
        keep_alive = True
        while keep_alive:
            firstline = readline(socket).strip()
            rematch = re.match("([A-Z]+) ([^ ]+) ?.*", firstline)

            if not rematch:
                raise Exception('Unexpected request')

            verb = rematch.group(1)
            url = rematch.group(2)

            # Skip headers
            keep_alive = False
            user_agent = ''
            while True:
                header = readline(socket).strip()
                if header == '':
                    break
                elif header.upper() == 'CONNECTION: KEEP-ALIVE':
                    keep_alive = True
                elif header.upper().startswith('USER-AGENT: '):
                    user_agent = header[len('USER-AGENT: '):]

            session_token = uuid.uuid4().hex
            log_append('tcp_http_requests', socket.getpeername()[0], dstport, verb, url, user_agent, session_token)

            socket.send("HTTP/1.0 200 OK\nServer: microhttpd (MontaVista/2.4, i386-uClibc)\nSet-Cookie: sessionToken={}; Expires={}\nContent-Type: text/html\nContent-Length: 38\nConnection: {}\n\nmicrohttpd on Linux 2.4, it works!\n\n".format(session_token, __getexpdate(5 * 365 * 24 * 60 * 60), "keep-alive" if keep_alive else "close"))
    except ssl.SSLError as err:
        print("SSL error: {}".format(err.reason))
        pass
    except Exception as err:
        #print(traceback.format_exc())
        pass

    try:
        print("-- HTTP TRANSPORT CLOSED --")
        socket.close()
    except:
        pass
common.py 文件源码 项目:pyNgrok 作者: aaronsh 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run(self):
        if self.sck_side_A is not None and self.sck_side_B is not None:
            logger = logging.getLogger("logger")
            logger.info("%s start"%self.getName())
            set_sock_buff_size(self.sck_side_A)
            set_sock_buff_size(self.sck_side_B)
            #send cached data
            if self.cached_data_from_A:
                self.send_all(self.sck_side_B, self.cached_data_from_A)
            if self.cached_data_from_B:
                self.send_all(self.sck_side_A, self.cached_data_from_B)
            scks = (self.sck_side_A, self.sck_side_B)
            while self.forwarding:
                try:
                    readable,writeable,exceptional = select.select(scks,[],scks, 1)
                    for s in readable:
                        data = recv(s, BUFFER_SIZE)
                        if len(data):
                            if s == self.sck_side_A:
                                #self.sck_side_B.sendall(data)
                                self.send_all(self.sck_side_B, data)
                            else:
                                #self.sck_side_A.sendall(data)
                                self.send_all(self.sck_side_A, data)
                        else:
                            # remote closed
                            self.forwarding = False
                            break
                    for s in exceptional:
                        socket.getpeername()
                        peer_addr, peer_port = s.getpeername()
                        local_addr, local_port = s.getsockname(self)
                        logger.error("socket in exceptional %s:%d->%s:%d"%(local_addr, local_port, peer_addr, peer_port))
                        self.forwarding = False
                        break
                except socket.error,e:
                    logger.error(traceback.format_exc())
                    self.forwarding = False
                except Exception, e:
                    logger.error(traceback.format_exc())
                    self.forwarding = False
        if self.sck_side_A is not None:
            safe_close_socket(self.sck_side_A)
        if self.sck_side_B is not None:
            safe_close_socket(self.sck_side_B)
        logger.info("%s end"%self.getName())


问题


面经


文章

微信
公众号

扫码关注公众号