https://github.com/smallnest/mule
a hybird Conn which sends UDP packets and receives ICMP packets
https://github.com/smallnest/mule
Last synced: 29 days ago
JSON representation
a hybird Conn which sends UDP packets and receives ICMP packets
- Host: GitHub
- URL: https://github.com/smallnest/mule
- Owner: smallnest
- License: apache-2.0
- Created: 2024-05-12T10:16:29.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-02-06T04:31:11.000Z (3 months ago)
- Last Synced: 2025-03-19T06:43:04.799Z (about 1 month ago)
- Language: Go
- Size: 1.32 MB
- Stars: 7
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mule
  [](https://goreportcard.com/report/github.com/smallnest/mule) [](http://godoc.org/github.com/smallnest/mule)Mule is a Go library that provides a convenient way to send UDP packets to multiple remote servers with unreachable ports and receive ICMP Destination/Port Unreachable packets from those servers. This can be useful for network diagnostics, port scanning, or other network-related tasks.

## Features
- Send UDP packets to specified IP addresses and ports
- Receive and parse ICMP Destination Unreachable messages
- Configurable connection options (local IP, timeout, TOS, TTL, IPv4 flags)
- Easy-to-use API compatible with `net.Conn` interface## Installation
To install Mule, use `go get`:
```
go get github.com/smallnest/mule
```## Usage
Here's a basic example of how to use Mule:
```go
package mainimport (
"context"
"fmt"
"net"
"time"
)func main() {
muleConn, err := mule.New(
mule.WithLocalIP("192.168.1.1"),
mule.WithTimeout(5*time.Second),
mule.WithTTL(64),
mule.WithTOS(0),
mule.WithIPv4Flag(0),
)if err != nil {
log.Fatalf("failed to create mule connection: %v", err)
}defer muleConn.Close()
// send a UDP packet
_, err = muleConn.WriteToIP([]byte("Hello, Mule!"), "192.168.1.2", 1234, 80)
if err != nil {
log.Fatalf("failed to send UDP packet: %v", err)
}// read the ICMP response
dstIP, srcPort, dstPort, err := muleConn.ReadFrom()
if err != nil {
log.Fatalf("failed to read ICMP response: %v", err)
}
fmt.Printf("received ICMP response: dstIP=%s, srcPort=%d, dstPort=%d\n", dstIP, srcPort, dstPort)}
```