libpcap을 기반으로 핵심 분석 및 필터링 기능이 포함된 C 언어 네트워크 패킷 분석기를 개발합니다.
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) 조회 기능을 추가하세요. 합리적인 기본값과 함께 모든 옵션에 대한 커맨드라인 인수를 포함하세요. 가독성을 높이기 위해 색상 코딩된 출력을 구현하세요.
출처 · 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;
}[주요 확장 가이드]
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단계
이 개선안에 쓰인 기법 — 프롬프트 클래스에서 배우기
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.