scanner

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package scanner discovers devices on the local LAN. It does concurrent TCP-dial probes across a CIDR for a list of ports, plus optional ARP-table reads + HTTP banner grabs. No raw sockets — uses only stdlib net.Dial and `arp -a` / /proc/net/arp.

Index

Constants

This section is empty.

Variables

View Source
var DefaultPorts = []int{502, 1502, 8899, 6607, 80, 443, 1883, 8080}

DefaultPorts are common Modbus TCP and MQTT ports to scan.

Functions

func LocalCIDR

func LocalCIDR() string

LocalCIDR returns a best-effort /24 covering the host's primary non-loopback interface. Falls back to "192.168.1.0/24" if nothing is found. Used when the agent receives a scan request with no CIDR.

Types

type ArpEntry

type ArpEntry struct {
	IP  string `json:"ip"`
	MAC string `json:"mac"`
	OUI string `json:"oui,omitempty"`
}

ArpEntry represents a device found via ARP.

func ArpScan

func ArpScan(cidr string) ([]ArpEntry, error)

ArpScan discovers devices by reading the system ARP table. On macOS/Linux, it first does a TCP-dial sweep to populate the ARP cache, then reads the ARP table.

type HTTPBanner

type HTTPBanner struct {
	IP           string `json:"ip"`
	Port         int    `json:"port"`
	StatusCode   int    `json:"status_code"`
	ServerHeader string `json:"server_header,omitempty"`
	Title        string `json:"title,omitempty"`
	BodySnippet  string `json:"body_snippet,omitempty"`
}

HTTPBanner contains information gathered from an HTTP probe.

func HTTPProbe

func HTTPProbe(ip string, port int) (*HTTPBanner, error)

HTTPProbe probes a single host:port for HTTP banners.

func HTTPProbeBatch

func HTTPProbeBatch(hosts []Host) []HTTPBanner

HTTPProbeBatch probes multiple hosts for HTTP banners concurrently.

type Host

type Host struct {
	IP       string `json:"ip"`
	Port     int    `json:"port"`
	Duration string `json:"duration"`
}

Host represents a discovered host with an open port.

func ScanSubnetMultiPort

func ScanSubnetMultiPort(cidr string, ports []int, timeout time.Duration) ([]Host, error)

ScanSubnetMultiPort scans a subnet for multiple ports.

type Interface

type Interface struct {
	Name    string   `json:"name"`
	Subnets []string `json:"subnets"`
}

Interface represents a network interface with its subnets.

func GetInterfaces

func GetInterfaces() ([]Interface, error)

GetInterfaces returns all non-loopback network interfaces with IPv4 subnets.

Jump to

Keyboard shortcuts

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