{"id":50301988,"url":"https://github.com/smallnest/goscapy","last_synced_at":"2026-05-28T13:09:07.059Z","repository":{"id":358777853,"uuid":"1242218949","full_name":"smallnest/goscapy","owner":"smallnest","description":"A Go port of Scapy","archived":false,"fork":false,"pushed_at":"2026-05-19T04:24:42.000Z","size":101,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-19T04:26:22.407Z","etag":null,"topics":["network","network-programming","packet-capture","packet-sniffer","scapy","tcp-ip"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smallnest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-18T08:22:55.000Z","updated_at":"2026-05-19T04:24:46.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/smallnest/goscapy","commit_stats":null,"previous_names":["smallnest/goscapy"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/smallnest/goscapy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fgoscapy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fgoscapy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fgoscapy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fgoscapy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smallnest","download_url":"https://codeload.github.com/smallnest/goscapy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smallnest%2Fgoscapy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33609479,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-28T02:00:06.440Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["network","network-programming","packet-capture","packet-sniffer","scapy","tcp-ip"],"created_at":"2026-05-28T13:09:06.652Z","updated_at":"2026-05-28T13:09:07.042Z","avatar_url":"https://github.com/smallnest.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# goscapy\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/smallnest/goscapy.svg)](https://pkg.go.dev/github.com/smallnest/goscapy)\n[![CI](https://github.com/smallnest/goscapy/actions/workflows/ci.yml/badge.svg)](https://github.com/smallnest/goscapy/actions/workflows/ci.yml)\n[![Go Version](https://img.shields.io/badge/Go-%3E%3D1.26-blue)](https://go.dev/)\n[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)\n\nA pure Go library for crafting, dissecting, sending, receiving, and sniffing network packets. goscapy provides an idiomatic Go API with type-safe builders and one-liner shortcut functions.\n\n## Features\n\n- **Builder API** — fluent method chaining for type-safe, explicit packet construction\n- **Shortcut Functions** — one-liners for common protocol stacks with sensible defaults\n- **Packet Dissect** — parse raw bytes into structured packets with auto protocol detection\n- **Send \u0026 Receive** — send and receive packets via raw sockets (L2 and L3)\n- **Packet Sniffing** — capture live traffic with callback or channel-based APIs, plus BPF filter support\n- **Auto Checksums** — IP, TCP, UDP, and ICMP checksums are computed automatically during serialization\n- **Layer Binding** — automatic field inference between adjacent layers (e.g., IP over Ethernet → EtherType=0x0800)\n- **Cross-Platform** — Darwin (macOS) and Linux with platform-specific raw socket implementations\n\n## Supported Protocols\n\n| Layer | Protocols |\n|-------|-----------|\n| Link | Ethernet, ARP |\n| Network | IPv4 |\n| Transport | TCP, UDP, ICMP |\n| Payload | Raw |\n\n## Installation\n\n```bash\ngo get github.com/smallnest/goscapy\n```\n\n## Quick Start\n\n### Build a Packet (Builder API)\n\n```go\n// Ethernet + IP + ICMP Echo Request\npkt, err := goscapy.NewEthernet().\n    SrcMAC(\"aa:bb:cc:dd:ee:ff\").\n    DstMAC(\"ff:ff:ff:ff:ff:ff\").\n    Over(goscapy.NewIP().SrcIP(\"192.168.1.1\").DstIP(\"8.8.8.8\")).\n    Over(goscapy.NewICMP().Type(8).Code(0)).\n    Build()\n```\n\n### Build a Packet (Shortcut)\n\n```go\n// Same as above, in one line\npkt, err := goscapy.EtherIPICMP(\"ff:ff:ff:ff:ff:ff\", \"8.8.8.8\", 8, 0)\n```\n\n### Dissect a Packet\n\n```go\nraw := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ...} // raw bytes\npkt, err := packet.Dissect(raw, packet.DissectEthernet)\nfmt.Println(pkt.String()) // \"Ethernet / IP / ICMP\"\n```\n\n### Send a Packet\n\n```go\npkt, _ := goscapy.EtherIPICMP(\"ff:ff:ff:ff:ff:ff\", \"8.8.8.8\", 8, 0)\nsendrecv.Send(pkt, \"eth0\")  // send at L3 (IP level)\nsendrecv.Sendp(pkt, \"eth0\") // send at L2 (Ethernet)\n```\n\n### Sniff Packets\n\n```go\n// Callback-based\nsniff.Sniff(sniff.SniffConfig{\n    Iface:   \"eth0\",\n    Filter:  \"icmp\",\n    Timeout: 10 * time.Second,\n}, func(pkt *packet.Packet) bool {\n    fmt.Println(pkt)\n    return true // continue sniffing\n})\n\n// Channel-based\nch, stop := sniff.SniffChan(sniff.SniffConfig{Iface: \"eth0\", Count: 5})\ndefer stop()\nfor pkt := range ch {\n    fmt.Println(pkt)\n}\n```\n\n## Documentation\n\nFull documentation is available at [pkg.go.dev/github.com/smallnest/goscapy](https://pkg.go.dev/github.com/smallnest/goscapy).\n\n### Packages\n\n| Package | Description |\n|---------|-------------|\n| `pkg/goscapy` | Builder API and shortcut functions |\n| `pkg/packet` | Core packet/layer types, build, dissect, field binding |\n| `pkg/layers` | Protocol layer definitions (Ethernet, ARP, IP, TCP, UDP, ICMP, Raw) |\n| `pkg/sendrecv` | Raw socket send/receive (Send, Sendp, Recv, SendRecv) |\n| `pkg/sniff` | Packet sniffing with BPF filter support |\n| `pkg/fields` | Field type system (serialization, deserialization) |\n\n### Shortcut Functions\n\n| Function | Protocol Stack |\n|----------|---------------|\n| `EtherIP` | Ethernet + IPv4 + Payload |\n| `EtherIPICMP` | Ethernet + IPv4 + ICMP |\n| `EtherIPTCP` | Ethernet + IPv4 + TCP |\n| `EtherIPUDP` | Ethernet + IPv4 + UDP |\n| `EtherARP` | Ethernet + ARP |\n| `IPICMP` | IPv4 + ICMP (no Ethernet) |\n| `IPTCP` | IPv4 + TCP (no Ethernet) |\n| `IPUDP` | IPv4 + UDP (no Ethernet) |\n\n### Builders\n\n| Builder | Key Methods |\n|---------|-------------|\n| `EthernetBuilder` | `SrcMAC`, `DstMAC`, `Type` |\n| `IPBuilder` | `SrcIP`, `DstIP`, `TTL`, `Proto`, `ID` |\n| `ICMPBuilder` | `Type`, `Code`, `ID`, `Seq` |\n| `TCPBuilder` | `SrcPort`, `DstPort`, `Flags`, `Seq`, `Ack`, `Window` |\n| `UDPBuilder` | `SrcPort`, `DstPort` |\n| `ARPBuilder` | `Op`, `SrcMAC`, `SrcIP`, `DstMAC`, `DstIP` |\n\n## Platform Support\n\n| Platform | L2 Send/Recv | L3 Send/Recv | BPF Filter | Loopback |\n|----------|:------------:|:------------:|:----------:|:--------:|\n| macOS (Darwin) | BPF | AF_INET | kernel BPF | lo0 |\n| Linux | AF_PACKET | AF_INET | SO_ATTACH_FILTER | lo |\n\n## Requirements\n\n- Go 1.26+\n- macOS or Linux\n- Root/administrator privileges for raw socket operations\n- `tcpdump` (optional, for BPF filter string compilation via `sniff.CompileFilter`)\n\n## Makefile\n\n```bash\nmake build         # Build all packages\nmake test          # Run all tests\nmake test-race     # Run tests with race detector\nmake test-cover    # Run tests with coverage profile\nmake bench         # Run benchmarks\nmake lint          # Run golangci-lint\nmake fmt           # Format code\nmake vet           # Run go vet\nmake check         # Run fmt + vet + lint + test\n```\n\n## License\n\nMIT License. See [LICENSE](LICENSE) for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Fgoscapy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmallnest%2Fgoscapy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmallnest%2Fgoscapy/lists"}