[실습 2] libpcap

1. 필요 소프트웨어 설치

  1. sudo apt install libpcap-dev

  2. pip3 install Cython

  3. pip3 install python-libpcap

2. 실습 및 과제 & 슬라이드 자료

실습

  • python-libpcap을 사용하여 패킷 캡처

  • python의 struct 모듈을 이용하여 바이트 데이터 복호화

    • 캡처한 패킷의 ethernet header 정보 출력

과제

  • python 모듈인 python-libpcap을 사용하여 헤더 정보 출력 (10점)

    • python-libpcap을 사용한 패킷 캡처

      • Ethernet 헤더 정보 캡처 (2.5점)

      • IP 헤더 정보 캡처 (2.5점)

      • TCP 헤더 정보 캡처 (2.5점)

      • UDP 헤더 정보 캡처 (2.5점)
        [ TCP, UDP 헤더 구분을 IP 헤더 정보에서 if-then 규칙 사용 ]

2. Packet Cature

2-1. 강의 영상 (Youtube)

  1. 실습 1

2. 실습 2

3. 과제

3. 자주 묻는 질문 & 답변

  1. "struct.error: unpack requires a buffer of N bytes" 오류 발생

    • "struct.unpack(format, data)"에서 data에 길이에 맞춰 format의 standard size를 맞추지 않아 발생하는 오류

    • 실습 슬라이드 11페이지 표 참고

  2. "IndexError: tuple index out of range" 오류 발생

    • tuple(구조체)의 index가 범위를 벗어나 발생하는 오류

    • ex) tuple = (1, 2, 3) -> tuple[3]일 경우 오류 발생