mule

package module
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

Mule

GitHub GitHub Action Go Report Card GoDoc

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:

package main

import (
	"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)

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a Mule connection. You can use it to send UDP packets to multiple remote servers with unreachable ports. Then you receive ICMP Destination/Port Unreachable packets from the remote servers.

func New

func New(opts ...OptionFn) (*Conn, error)

New creates a new Mule connection with the given options.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the Mule connection and releases associated resources.

func (*Conn) ReadFrom

func (c *Conn) ReadFrom() (string, uint16, uint16, error)

ReadFrom reads ICMP data from the remote server and returns the destination IP, source port, and destination port.

func (*Conn) WriteToIP

func (c *Conn) WriteToIP(payload []byte, remoteIP string, localPort, remotePort uint16) (int, error)

WriteToIP writes UDP data to the specified destination IP and port.

type IPv4Flag

type IPv4Flag uint8

IPv4Flag represents the flags in an IPv4 header.

type OptionFn

type OptionFn func(*Conn)

OptionFn is a function type for configuring Conn options

func WithIPv4Flag

func WithIPv4Flag(flag IPv4Flag) OptionFn

WithIPv4Flag sets the IPv4 flag for the connection

func WithLocalIP

func WithLocalIP(localIP string) OptionFn

WithLocalIP sets the local IP address for the connection

func WithTOS

func WithTOS(tos uint8) OptionFn

WithTOS sets the Type of Service (TOS) for the connection

func WithTTL

func WithTTL(ttl uint8) OptionFn

WithTTL sets the Time To Live (TTL) for the connection

func WithTimeout

func WithTimeout(timeout time.Duration) OptionFn

WithTimeout sets the timeout duration for the connection

Directories

Path Synopsis
examples
mule command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL