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
评论列表
文章目录