net

package
v0.0.0-...-e36ac40 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2024 License: MulanPSL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IP_REG        = `^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$`
	CIDR_REG      = `` /* 130-byte string literal not displayed */
	FULL_CIDR_REG = `` /* 212-byte string literal not displayed */
	RANGE_REG     = `` /* 212-byte string literal not displayed */
)
View Source
const INTERFACE_IP_LIST_OID = `.1.3.6.1.2.1.4.20.1.2`

Variables

View Source
var (
	Network GalangNet
	SNMP    GalangSNMP
	NMAP    GalangNMAP
)
View Source
var InterfaceStatus_name = map[int32]string{
	1: "UP",
	2: "DOWN",
	3: "Testing",
	4: "Unknown",
	5: "Dormant",
	6: "NotPresent",
}
View Source
var InterfaceStatus_value = map[string]int32{
	"UP":         1,
	"DOWN":       2,
	"Testing":    3,
	"Unknown":    4,
	"Dormant":    5,
	"NotPresent": 6,
}
View Source
var ScannerStatus_name = map[int32]string{
	1: "Created",
	2: "Pending",
	3: "Running",
	4: "Success",
	5: "Error",
}
View Source
var ScannerStatus_value = map[string]int32{
	"Created": 1,
	"Pending": 2,
	"Running": 3,
	"Success": 4,
	"Error":   5,
}
View Source
var System_obj = map[string]string{
	".1.3.6.1.2.1.1.1.0": "sysDescr",
	".1.3.6.1.2.1.1.2.0": "sysObjectID",
	".1.3.6.1.2.1.1.3.0": "sysUpTime",
	".1.3.6.1.2.1.1.4.0": "sysContact",
	".1.3.6.1.2.1.1.5.0": "sysName",
	".1.3.6.1.2.1.1.6.0": "sysLocation",
}
View Source
var System_oid = map[string]string{
	"sysDescr":    ".1.3.6.1.2.1.1.1.0",
	"sysObjectID": ".1.3.6.1.2.1.1.2.0",
	"sysUpTime":   ".1.3.6.1.2.1.1.3.0",
	"sysContact":  ".1.3.6.1.2.1.1.4.0",
	"sysName":     ".1.3.6.1.2.1.1.5.0",
	"sysLocation": ".1.3.6.1.2.1.1.6.0",
}
View Source
var System_oids = []string{System_oid[`sysDescr`], System_oid[`sysObjectID`], System_oid[`sysUpTime`], System_oid[`sysContact`], System_oid[`sysName`], System_oid[`sysLocation`]}

Functions

This section is empty.

Types

type GalangNMAP

type GalangNMAP byte

func (*GalangNMAP) NewScanner

func (*GalangNMAP) NewScanner(target, user string) (*Scanner, error)

NewScanner 新建一个扫描器

type GalangNet

type GalangNet byte

func (*GalangNet) GetCIDRAvailableAddrList

func (*GalangNet) GetCIDRAvailableAddrList(cidr string) ([]string, error)

GetCIDRAvailableAddrList retrun available ip address list

func (*GalangNet) GetExternalIP

func (*GalangNet) GetExternalIP() (string, error)

GetExternalIP 获取公网IP地址

func (*GalangNet) GetLocalIPv4

func (*GalangNet) GetLocalIPv4() (string, error)

GetLocalIPv4 获取本机ipv4地址

func (*GalangNet) GetRangeAddrList

func (*GalangNet) GetRangeAddrList(_range string) ([]string, error)

GetRangeAddrList 获取一个范围里的ip地址 192.168.1.222-192.168.1.228

func (*GalangNet) GetSystemUUIDForLinux

func (*GalangNet) GetSystemUUIDForLinux() (string, error)

GetSystemUUIDForLinux get linux dmidecode -s system-uuid

func (*GalangNet) IP2long

func (*GalangNet) IP2long(ipstr string) (uint32, error)

IP2long .

func (*GalangNet) IPSFormat

func (*GalangNet) IPSFormat(target string) ([]string, error)

GetIPSFormat will format target string to a valid string array if target is a ip like 192.168.1.222 will format ['192.168.1.222'] if target is a range of ip like 192.168.1.222[-||~]192.168.1.224 will format ['192.168.1.222','192.168.1.223','192.168.1.224']

func (*GalangNet) IsRangeOf

func (*GalangNet) IsRangeOf(addr, cidr string) (bool, error)

IsRangeOf if addr is range of cidr returns true

func (*GalangNet) LPM

func (n *GalangNet) LPM(ip string, subnets []string) (string, error)

LPM return Longest prefix match

func (*GalangNet) Long2ip

func (*GalangNet) Long2ip(ip uint32) string

Long2ip .

func (*GalangNet) MaskLengthToNetmask

func (*GalangNet) MaskLengthToNetmask(cidr int) (string, error)

MaskLengthToNetmask 24 >>> 255.255.255.0

func (*GalangNet) NetmaskToMaskLength

func (*GalangNet) NetmaskToMaskLength(netmask string) (int, error)

NetmaskToMaskLength 255.255.255.0 >>> 24

type GalangSNMP

type GalangSNMP byte

func (*GalangSNMP) NewSnmpWrapper

func (*GalangSNMP) NewSnmpWrapper(target, community string, version gosnmp.SnmpVersion, timeout int64) (*SNMPWrapper, error)

type Host

type Host struct {
	Address []nmap.Address `json:"addresses"`
	Ports   []nmap.Port    `json:"ports"`
}

type HostResult

type HostResult struct {
	Total int32  `json:"total"`
	Up    int32  `json:"up"`
	Down  int32  `json:"down"`
	Hosts []Host `json:"hosts"`
}

type Interface

type Interface struct {
	Name       string          `json:"name,omitempty"`
	MacAddress string          `json:"mac_addr,omitempty"`
	IPv4       string          `json:"ip,omitempty"`
	NetMask    string          `json:"netmask,omitempty"`
	Status     InterfaceStatus `json:"status,omitempty"`
}

func (*Interface) ToString

func (intf *Interface) ToString() string

type InterfaceStatus

type InterfaceStatus int32
const (
	UP         InterfaceStatus = 1
	DOWN       InterfaceStatus = 2
	Testing    InterfaceStatus = 3
	Unknown    InterfaceStatus = 4
	Dormant    InterfaceStatus = 5
	NotPresent InterfaceStatus = 6
)

The current operational state of the interface. The testing(3) state indicates that no operational packets can be passed. If ifAdminStatus is down(2) then ifOperStatus should be down(2). If ifAdminStatus is changed to up(1) then ifOperStatus should change to up(1) if the interface is ready to transmit and receive network traffic; it should change to dormant(5) if the interface is waiting for external actions (such as a serial line waiting for an incoming connection); it should remain in the down(2) state if and only if there is a fault that prevents it from going to the up(1) state; it should remain in the notPresent(6) state if the interface has missing (typically, hardware) components.

func (InterfaceStatus) String

func (x InterfaceStatus) String() string

type SNMPWrapper

type SNMPWrapper struct {
	Client *gosnmp.GoSNMP
}

func (*SNMPWrapper) Interfaces

func (wrap *SNMPWrapper) Interfaces() ([]Interface, error)

func (*SNMPWrapper) SystemInfo

func (wrap *SNMPWrapper) SystemInfo() (*System, error)

type Scanner

type Scanner struct {
	Id        string        `json:"id"`
	Targets   []string      `json:"targets"`
	StartTime time.Time     `json:"start_at"`
	EndTime   time.Time     `json:"end_at"`
	Status    ScannerStatus `json:"status"`
	Message   string        `json:"message"`
	User      string        `json:"user"`
	Result    nmap.Run      `json:"result"`
	Warnings  []string      `json:"warnings"`
}

func (*Scanner) Hosts

func (sc *Scanner) Hosts() HostResult

func (*Scanner) Scanner

func (sc *Scanner) Scanner(options ...func(*nmap.Scanner)) (*Scanner, error)

Scanner will scan target ip or subnet

type ScannerStatus

type ScannerStatus int32
const (
	Created ScannerStatus = 1
	Pending ScannerStatus = 2
	Running ScannerStatus = 3
	Success ScannerStatus = 4
	Error   ScannerStatus = 5
)

func (ScannerStatus) String

func (x ScannerStatus) String() string

type SubnetInfo

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

SubnetInfo apache subnetutils for go version

func NewSubnetInfo

func NewSubnetInfo(cidr string) (*SubnetInfo, error)

NewSubnetInfo 创建一个subnetInfo对象

func (*SubnetInfo) AddressString

func (sub *SubnetInfo) AddressString() string

AddressString 获取ip地址

func (*SubnetInfo) BradcastString

func (sub *SubnetInfo) BradcastString() string

BradcastString 获取广播地址

func (*SubnetInfo) GetCidrSignature

func (sub *SubnetInfo) GetCidrSignature() string

GetCidrSignature 获取无分类地址

func (*SubnetInfo) HighAddress

func (sub *SubnetInfo) HighAddress() string

HighAddress return the last available address in current subnet

func (*SubnetInfo) IsRangeOf

func (sub *SubnetInfo) IsRangeOf(addr string) (bool, error)

IsRangeOf 判断输入的ip是否在当前网段内

func (*SubnetInfo) LowAddress

func (sub *SubnetInfo) LowAddress() string

LowAddress return the first available address in current subnet

func (*SubnetInfo) NetmaskString

func (sub *SubnetInfo) NetmaskString() string

NetmaskString 获取子网掩码

func (*SubnetInfo) NetworkString

func (sub *SubnetInfo) NetworkString() string

NetworkString 获取网络地址

func (*SubnetInfo) Size

func (sub *SubnetInfo) Size() uint32

Size returns available ip address size

func (*SubnetInfo) ToString

func (s *SubnetInfo) ToString() string

ToString 返回SubnetInfo的数据

type System

type System struct {
	Hostname    string
	Location    string
	Contract    string
	Vendor      string
	UpTime      int
	Description string
}

Jump to

Keyboard shortcuts

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