Programming/Python

Python hexdump 구현

Tribal 2017. 10. 17. 15:23

소스코드

1
2
3
4
5
6
def hexdump(string):
    for line in range(0, ((len(string)/16)+1), 1):
        print '%04x: ' % line + ' '.join(x.encode('hex'for x in string[(line*16):((line*16)+16)])
    #print ' '.join(x.encode('hex') for x in string)
 
hexdump("A"*100+"B"*100)
cs


결과


사용방법 : 소스코드의 6번째 줄처럼

socket이나 페이로드를 구현할 때 쓸만할거 같아서 작성했다. 4번째 줄처럼 바로 보는 방법도 있지만, 보기 불편하므로...



ps. hexdump 모듈이 있는거 같지만 따로 설치해야 하는거 같다.