C 패킷 분석 CLI 작성
libpcap을 기반으로 핵심 분석 및 필터링 기능이 포함된 C 언어 네트워크 패킷 분석기를 개발합니다.
- 추천 툴
- Claude CodeAI 분류
- 쓰인 기법
- 명세 상세화 및 기능 열거
프롬프트 원문
Create a command-line network packet analyzer in C using libpcap. Implement packet capture from network interfaces with filtering options. Add protocol analysis for common protocols (TCP, UDP, HTTP, DNS, etc.). Include traffic statistics with bandwidth usage and connection counts. Implement packet decoding with detailed header information. Add export functionality in PCAP and CSV formats. Include alert system for suspicious traffic patterns. Implement connection tracking with state information. Add geolocation lookup for IP addresses. Include command-line arguments for all options with sensible defaults. Implement color-coded output for better readability.
한국어 풀이 보기(참고용)
libpcap을 사용하여 C 언어로 커맨드라인 네트워크 패킷 분석기를 생성하세요. 필터링 옵션과 함께 네트워크 인터페이스에서의 패킷 캡처를 구현하세요. 주요 프로토콜(TCP, UDP, HTTP, DNS 등)에 대한 프로토콜 분석 기능을 추가하세요. 대역폭 사용량 및 연결 수와 함께 트래픽 통계를 포함하세요. 상세한 헤더 정보가 포함된 패킷 디코딩을 구현하세요. PCAP 및 CSV 형식의 내보내기 기능을 추가하세요. 의심스러운 트래픽 패턴에 대한 경고 시스템을 포함하세요. 상태 정보가 포함된 연결 추적을 구현하세요. IP 주소에 대한 위치(Geolocation) 조회 기능을 추가하세요. 합리적인 기본값과 함께 모든 옵션에 대한 커맨드라인 인수를 포함하세요. 가독성을 높이기 위해 색상 코딩된 출력을 구현하세요.
- 활용빌드 환경(예: GCC, OS) 및 libpcap 라이브러리 버전을 명시하면 좋습니다.
- 활용코드 생성 후 모듈별로 파일 분리를 요청해 구조를 깔끔하게 다듬으세요.
출처 · prompts.chat · Network Packet Analyzer CLI — 원문은 출처에 게시된 그대로이며, 권리는 원작자에게 있습니다.
텍스트 결과
Gemini로 실행한 결과입니다. 입력 항목에는 국내 환경의 예시값을 적용했습니다(AI 생성 — 사실 확인 필요).
실행 입력값 보기
Create a command-line network packet analyzer in C using libpcap. Implement packet capture from network interfaces with filtering options. Add protocol analysis for common protocols (TCP, UDP, HTTP, DNS, etc.). Include traffic statistics with bandwidth usage and connection counts. Implement packet decoding with detailed header information. Add export functionality in PCAP and CSV formats. Include alert system for suspicious traffic patterns. Implement connection tracking with state information. Add geolocation lookup for IP addresses. Include command-line arguments for all options with sensible defaults. Implement color-coded output for better readability.
libpcap 라이브러리를 활용한 C 언어 네트워크 패킷 분석기의 기본 골격 예시입니다.
#include <pcap.h>
#include <stdio.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
// 패킷 처리 콜백 함수
void process_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet) {
struct ip *ip_hdr = (struct ip *)(packet + 14); // Ethernet 헤더 제외
char src_ip[INET_ADDRSTRLEN], dst_ip[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &(ip_hdr->ip_src), src_ip, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(ip_hdr->ip_dst), dst_ip, INET_ADDRSTRLEN);
// 색상 출력 (ANSI Code)
printf("\033[1;32m[PACKET]\033[0m %s -> %s | Protocol: %d | Len: %d
",
src_ip, dst_ip, ip_hdr->ip_p, header->len);
// TODO: CSV/PCAP 저장, GeoIP 조회, 이상 징후 알림 및 세션 추적 구현
}
int main(int argc, char *argv[]) {
char errbuf[PCAP_ERRBUF_SIZE];
char *dev = "eth0"; // getopt()로 CLI 인자 처리 권장
pcap_t *handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);
if (!handle) return 1;
struct bpf_program fp;
pcap_compile(handle, &fp, "ip", 0, PCAP_NETMASK_UNKNOWN);
pcap_setfilter(handle, &fp);
printf("패킷 분석 시작 (%s)...
", dev);
pcap_loop(handle, 10, process_packet, NULL);
pcap_close(handle);
return 0;
}[주요 확장 가이드]
- getopt_long()으로 커맨드라인 옵션(-i 인터페이스, -f 필터 등)을 파싱합니다.
- MaxMind GeoIP2 C SDK로 IP 위치를 조회합니다.
- 의심 트래픽 감지(포트스캔 등) 시 색상 처리된 경고 문구를 출력하고 CSV 파일로 기록합니다.
mopick 개선안
원문을 더 잘 동작하게 고쳐 쓴 프롬프트
원문을 그대로 넣으면 AI 가 매번 다르게 답하거나 중요한 부분을 빠뜨릴 수 있습니다. 개선안은 원문의 뜻과 언어는 그대로 두고 역할 · 바꿔 넣을 입력 칸 · 결과 형식 · 지킬 조건을 보완해 다시 쓴 버전입니다. 원문과 같은 곳(ChatGPT · Claude 등)에 그대로 붙여 넣어 쓰면 됩니다.
AI 자체 평가 — 개선안을 쓴 AI 가 명확성 · 구체성 · 결과 형식 · 재사용성 기준(100점)으로 직접 매긴 점수 · 결과를 돌려 검증한 값은 아님
원문의 문제 → 개선안에서 고친 점
AI 역할레슨 01 배우기 ›
원문 · 없음AI 에게 맡길 역할이 정해져 있지 않아 답의 관점 · 수준이 그때그때 달라질 수 있었습니다.
개선 · 역할을 정함Act as an expert C systems programmer. Create a modular, production-ready command-line net
입력 칸레슨 05 배우기 ›
원문 · 없음바꿔 넣을 자리가 표시돼 있지 않아 쓸 때마다 원문을 직접 고쳐야 했습니다.
개선 · 1개[GEOLOCATION_LIB, e.g., libmaxminddb]
작업 순서레슨 07 배우기 ›
원문 · 없음작업 순서가 정해져 있지 않아 AI 가 순서를 스스로 정해야 했습니다.
개선 · 5단계
고친 이유 (개선안을 만든 AI 의 설명)
- 1개발자 역할 명시 및 모듈화된 파일 구조와 Makefile 요구 추가
- 2외부 라이브러리 지정을 위한 [대괄호] 플레이스홀더 추가
- 3기능별 단계를 구조화하고 예외 처리 및 출력 형식 명확화
이 개선안에 쓰인 기법 — 프롬프트 클래스에서 배우기
01역할 정하기03결과 모양 정하기04지킬 조건 걸기05입력 칸으로 템플릿 만들기07작업을 단계로 나누기09구역을 나눠 쓰기
원문
Create a command-line network packet analyzer in C using libpcap. Implement packet capture from network interfaces with filtering options. Add protocol analysis for common protocols (TCP, UDP, HTTP, DNS, etc.). Include traffic statistics with bandwidth usage and connection counts. Implement packet decoding with detailed header information. Add export functionality in PCAP and CSV formats. Include alert system for suspicious traffic patterns. Implement connection tracking with state information. Add geolocation lookup for IP addresses. Include command-line arguments for all options with sensible defaults. Implement color-coded output for better readability.
개선안 · 색칠한 [칸]에 내 내용을 넣어 쓰세요
Act as an expert C systems programmer. Create a modular, production-ready command-line network packet analyzer in C using `libpcap`. Provide clean code architecture (separate `.h` and `.c` files) covering: 1. **Capture & Filtering:** Interface selection and custom BPF filters. 2. **Decoding & Tracking:** Detailed parsing for TCP, UDP, HTTP, and DNS with stateful connection tracking. 3. **Analytics & Alerts:** Real-time bandwidth/connection stats, basic anomaly alerts, and IP geolocation using `[GEOLOCATION_LIB, e.g., libmaxminddb]`. 4. **Export & UI:** Color-coded CLI output and export options for PCAP and CSV formats. 5. **CLI Options:** `getopt_long` argument parsing with sensible defaults. **Output Requirements:** - Provide a clear project structure, code for core components, and a functional `Makefile`. - Include robust error handling and proper memory/pcap cleanup.
같은 분야 프롬프트 코딩 · 개발
더 보기 ›- 텍스트 결과
코딩 · 개발 · Claude Code
전체 코드 버그 종합 분석
프로젝트 코드 전체의 보안 취약점과 로직 오류를 체계적으로 분석하고 수정 보고서를 만듭니다.
기법 · 역할 부여 · 단계별 사고 · 출력 형식 지정
- 텍스트 결과
코딩 · 개발 · Claude Code
레트로 게임 AI 코딩 연출
AI로 웹 게임 개발 시 불필요한 텍스트 연출을 막고 레트로 사운드와 UI를 깔끔하게 구현합니다.
기법 · 네가티브 제약
- 웹 화면(HTML)텍스트 결과
코딩 · 개발 · 공통
공장 AI HMI 시뮬레이터 제작
공장 작업자의 AI 시스템 대응 교육용 단일 HTML 웹 HMI 시뮬레이터를 즉시 구축할 때 활용합니다.
기법 · 역할 부여 · 단계별 지시 · 출력 형식 지정

