iprd

package
v0.1.0-test5 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 21 Imported by: 0

README

iprd

This package serves as the core library for the IP Reporter daemon (iprd). It provides all the necessary tooling to sniff IP Report packets from ASIC miners on a local network.

Documentation

Run go doc -http for more information on what is included.

Example Usage
func main() {
	// getting a network interface
	iface, err := iprd.GetInterfaceByName("eth0")
	if err != nil {
			log.Fatal(err)
	}
	// initializing and activating a IPRListener on iface
	listener := iprd.NewListener(nil, false, iface)
	if err := listener.Activate(); err != nil {
			log.Fatal(err)
	}
	// start listening
	listener.Listen()
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ValidIP     = regexp.MustCompile(`\b(?:(?:2(?:[0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9])\.){3}(?:(?:2([0-4][0-9]|5[0-5])|[0-1]?[0-9]?[0-9]))\b`)
	ValidMAC    = regexp.MustCompile(`([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})`)
	MsgPatterns = map[string]*regexp.Regexp{
		"Common": regexp.MustCompile(fmt.Sprintf(`^%s,%s`, ValidIP, ValidMAC)),
		"IR":     regexp.MustCompile(fmt.Sprintf(`^addr:%s`, ValidIP)),
		"BT":     regexp.MustCompile(fmt.Sprintf(`^IP:%sMAC:%s`, ValidIP, ValidMAC)),
		"DG":     regexp.MustCompile(`^DG_IPREPORT_ONLY`),
	}
)

Functions

func ParseIPReportPacket

func ParseIPReportPacket(packet *IPReportPacket) error

ParseIPReportPacket analysis packet for valid IP Report packet. Returns an error on failure.

Types

type IPRBroadcast

type IPRBroadcast struct {
	Msgs chan []byte
	Errs chan error
	// contains filtered or unexported fields
}

func NewBroadcaster

func NewBroadcaster(logger *IPRLogger, port int) (*IPRBroadcast, error)

NewBroadcaster returns a new IPRBroadcast at specified port.

func (*IPRBroadcast) Listen

func (b *IPRBroadcast) Listen()

Listen accepts incoming clients and subscribes them for broadcasted messages.

type IPRBroadcastMessage

type IPRBroadcastMessage struct {
	Timestamp int64         `json:"timestamp"`
	PacketID  string        `json:"packetID"`
	DstPort   int           `json:"dstPort"`
	SrcIP     string        `json:"srcIP"`
	SrcMAC    string        `json:"srcMAC"`
	MinerHint MinerTypeHint `json:"minerHint"`
}

IPRBroadcastMessage describes the JSON message structure of a IPReportPacket.

type IPRInterface

type IPRInterface struct {
	Index        int
	Name         string
	FriendlyName string
	Description  string
	IPv4         net.IP
	HardwareAddr net.HardwareAddr
	Flags        net.Flags
}

IPRInterface describes a network interface supported for IP Report listening.

func FindLANInterface

func FindLANInterface() (*IPRInterface, error)

FindLANInterface returns the first IPRInterface marked as LAN, if any.

func GetInterfaceByName

func GetInterfaceByName(name string) (*IPRInterface, error)

GetInterfaceByName returns the IPRInterface matching name.

func (*IPRInterface) IPAddr

func (i *IPRInterface) IPAddr() string

IPAddr returns IPv4 as string.

func (*IPRInterface) IsLAN

func (i *IPRInterface) IsLAN() bool

IsLAN returns bool for if IPRInterface is marked as LAN interface.

func (*IPRInterface) IsUp

func (i *IPRInterface) IsUp() bool

IsUp returns bool for if IPRInterface is marked as UP.

func (*IPRInterface) MACAddr

func (i *IPRInterface) MACAddr() string

MACAddr returns HardwareAddr as string.

func (*IPRInterface) NetworkPrefix

func (i *IPRInterface) NetworkPrefix() string

NetworkPrefix returns the network prefix(leading two octets) of IPv4

type IPRListener

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

func NewListener

func NewListener(logger *IPRLogger, logDebug bool, filter bool, iface *IPRInterface) *IPRListener

NewListener returns a new IPRListener. If logger is nil, a new IPRLogger is created. Setting logDebug to true enables debug packet logging. Setting filter to true excludes 'unknown' MinerTypeHint.

func (*IPRListener) Activate

func (l *IPRListener) Activate() error

Activate sets a new active pcap handle on iface. This must be called once before Listen().

func (*IPRListener) Broadcast

func (l *IPRListener) Broadcast() chan []byte

Broadcast returns a channel of messages for broadcasting.

func (*IPRListener) Listen

func (l *IPRListener) Listen()

Listen will start reading packets from the active handle and sends the marshalled IPReportPacket to Broadcast().

type IPRLogger

type IPRLogger struct {
	*log.Logger
}

func NewLogger

func NewLogger() *IPRLogger

NewLogger returns a new IPRLogger to stdout.

func (*IPRLogger) Debug

func (l *IPRLogger) Debug(msg string)

func (*IPRLogger) Error

func (l *IPRLogger) Error(err error)

func (*IPRLogger) Fatal

func (l *IPRLogger) Fatal(err error)

func (*IPRLogger) Info

func (l *IPRLogger) Info(raw string)

func (*IPRLogger) Panic

func (l *IPRLogger) Panic(err error)

func (*IPRLogger) Warn

func (l *IPRLogger) Warn(raw string)

type IPReportGoldshell

type IPReportGoldshell struct {
	Version     string          `json:"version"`
	IPAddress   string          `json:"ip"`
	DHCP        string          `json:"dhcp"`
	Model       string          `json:"model"`
	CtrlBoardSN string          `json:"ctrlsn"`
	MACAddress  string          `json:"mac"`
	Netmask     string          `json:"mask"`
	Gateway     string          `json:"gateway"`
	BoardSNs    json.RawMessage `json:"cpbsn"`
	DNS         json.RawMessage `json:"dns"`
	Serial      string          `json:"boxsn"`
	Time        string          `json:"time"`
	LEDStatus   bool            `json:"ledstatus"`
}

IPReportGoldshell represents the JSON payload of IP report packet for Goldshell miners.

type IPReportPacket

type IPReportPacket struct {
	Timestamp      time.Time
	Length         int
	CaptureLength  int
	InterfaceIndex int
	SrcIP          string
	DstIP          string
	SrcMAC         string
	DstMAC         string
	SrcPort        int
	DstPort        int
	Datagram       []byte
	Payload        string
	MinerHint      MinerTypeHint
}

IPReportPacket represents a IP Report packet.

func NewIPReportPacket

func NewIPReportPacket(packet gopacket.Packet) (*IPReportPacket, error)

NewIPReportPacket initializes packet into IPReportPacket. Returns an error on failure.

func (*IPReportPacket) Marshal

func (r *IPReportPacket) Marshal() ([]byte, error)

Marshal returns the IPReportPacket data to marshalled IPRBroadcastMessage.

func (IPReportPacket) String

func (r IPReportPacket) String() string

String returns relevent IPReportPacket info as a string.

type IPReportSealminer

type IPReportSealminer struct {
	Info       SealMinerInfo
	Interfaces []SealMinerInterface
}

IPReportSealminer represents the JSON payload of IP Report packet for SealMiners

func (*IPReportSealminer) UnmarshalJSON

func (i *IPReportSealminer) UnmarshalJSON(data []byte) error

type MinerTypeHint

type MinerTypeHint string
const (
	UnknownType MinerTypeHint = "unknown"
	Antminer    MinerTypeHint = "antminer"
	Iceriver    MinerTypeHint = "iceriver"
	Whatsminer  MinerTypeHint = "whatsminer"
	Goldshell   MinerTypeHint = "goldshell"
	Sealminer   MinerTypeHint = "sealminer"
	Elphapex    MinerTypeHint = "elphapex"
	Auradine    MinerTypeHint = "auradine"
)

type Record

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

func NewRecord

func NewRecord(cap int) *Record

NewRecord returns a new Record with maximum size of cap.

func (*Record) Add

func (r *Record) Add(key string, record RecordEntry)

Add creates/updates a RecordEntry in Record. If capacity is reached, entries are removed in FIFO order.

func (*Record) Contains

func (r *Record) Contains(key string) bool

Contains returns bool for if key is present in Record.

func (*Record) Display

func (r *Record) Display()

Display prints the current RecordEntries and Length of record to stdout. Useful for logging/debugging.

func (*Record) Get

func (r *Record) Get(key string) *RecordEntry

Get returns RecordEntry of key.

func (*Record) Length

func (r *Record) Length() int

Length returns the length of Record.

type RecordEntry

type RecordEntry struct {
	SrcIP     string
	SrcMAC    string
	MinerHint MinerTypeHint
	CreatedAt int64
	UpdatedAt int64
}

RecordEntry represents an entry in Record

type SealMinerBoard

type SealMinerBoard struct {
	Serial     string `json:"SN"`
	BinVersion int    `json:"BinVer"`
	BinNumber  int    `json:"BinNum"`
}

type SealMinerInfo

type SealMinerInfo struct {
	MACAddress     string           `json:"MAC"`
	Type           string           `json:"Type"`
	Firmware       string           `json:"Firmware"`
	CtrlBoard      string           `json:"CtrlBoardVersion"`
	InterfaceCount int              `json:"NetInterfaceCnt"`
	Upgrade        int              `json:"UpgradeStatus"`
	CtrlBoardSN    string           `json:"MainBoardSN"`
	RatedPower     int              `json:"RatedInputPower"`
	PowerLimit     int              `json:"InputPowerLimit"`
	Boards         []SealMinerBoard `json:"BoardSNArray"`
}

type SealMinerInterface

type SealMinerInterface struct {
	Interface  string `json:"Interface"`
	Active     bool   `json:"Active"`
	DHCP       bool   `json:"DHCP"`
	IPAddress  string `json:"IPV4"`
	Netmask    string `json:"Netmask"`
	Gateway    string `json:"Gateway"`
	DNS1       string `json:"DNS1"`
	DNS2       string `json:"DNS2"`
	AutoReboot bool   `json:"AutoReboot"`
}

type TCPCommand

type TCPCommand struct {
	Command string `json:"command"`
}

TCPCommand describes a tcp command.

Jump to

Keyboard shortcuts

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