tcp_hexdump.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:honeypot 作者: fabio-d 项目源码 文件源码
def handle_tcp_hexdump(socket, dstport):
    FILTER = ''.join([(len(repr(chr(x))) == 3) and chr(x) or '.' for x in range(256)])
    length = 16

    c = 0
    for chars in recv_and_split_blocks(socket, length):
        hexstr = ' '.join(["%02x" % ord(x) for x in chars])
        printable = ''.join(["%s" % ((ord(x) <= 127 and FILTER[ord(x)]) or '.') for x in chars])
        print colored("%04x  %-*s  %-*s" % (c, length*3, hexstr, length, printable), 'red', 'on_yellow')
        c += len(chars)
    print colored("%04x" % c, 'red', 'on_yellow')

    try:
        print("-- TCP TRANSPORT CLOSED --")
        socket.close()
    except:
        pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号