Documentation ¶
Overview ¶
Package pScan provides all the port scanning capability and the Target and Targets type on which those scans can be performed. The result(s) are returned as MultiScanResult.
Index ¶
- Constants
- func AsyncNewTarget(targetAddress string, ports netUtil.Ports, ch chan *Target, ...)
- type HostName
- type MultiScanResult
- type NetworkLocation
- type PortResult
- type ScanResult
- type ScanResults
- type Target
- func (t Target) AvgRTT() time.Duration
- func (t *Target) ColorString() string
- func (t *Target) IsHost() (bool, error)
- func (t *Target) LookUpVendor()
- func (t *Target) Ping(count int, privileged bool) (*ping.Statistics, error)
- func (t *Target) QueryMac()
- func (t *Target) Resolve()
- func (t *Target) Scan() *ScanResult
- func (t *Target) String() string
- type TargetStatus
- type Targets
Constants ¶
const ( Online TargetStatus = iota OfflineFiltered Unknown Local NetworkLocation = iota Global UnknownLoc )
Variables ¶
This section is empty.
Functions ¶
func AsyncNewTarget ¶
func AsyncNewTarget(targetAddress string, ports netUtil.Ports, ch chan *Target, scanLock *semaphore.Weighted, privileged bool)
AsyncNewTarget asynchronously creates a pointer to an initialized instance of Target as defined by the targetAddress and ports. Before returning the Target over ch, it is resolved by calling Target.Resolve. If the resolve was successful, AsyncNewTarget will try to send a ping request by calling Target.Ping and to query the MAC-address and vendor name by calling Target.QueryMac and Target.LookUpVendor. scanLock is used to controls how many targets may be resolved simultaneously and privileged controls if the scan should be run either in a (more detailed) mode that require root privileges, or (in the less detailed) 'user' mode.
Types ¶
type MultiScanResult ¶
type MultiScanResult struct { // Resolved contains the ScanResults of resolved hosts Resolved ScanResults // Unresolved contains the unresolved Targets Unresolved Targets }
MultiScanResult represents the scan result of multiple Targets.
func (*MultiScanResult) ColorString ¶
func (m *MultiScanResult) ColorString() string
ColorString returns a colored string representation of the ScanResult pointer.
func (*MultiScanResult) CustomColorString ¶
func (m *MultiScanResult) CustomColorString(onlineOnly, showClosed bool) string
CustomColorString returns a colored string representation of the ScanResult pointer. The parameter onlineOnly controls if targets not confirmed as online will be incorporated into the string. showClosed controls if closed and filtered ports also will be incorporated into the string.
func (*MultiScanResult) String ¶
func (m *MultiScanResult) String() string
String returns a string representation of the MultiScanResult pointer.
type NetworkLocation ¶
type NetworkLocation int
NetworkLocation is an integer representing the Target location inside the network. The values can be Local, Global or UnknownLoc.
func (NetworkLocation) ColorString ¶
func (n NetworkLocation) ColorString() string
ColorString returns a colored string representation of NetworkLocation.
func (NetworkLocation) String ¶
func (n NetworkLocation) String() string
String returns a string representation of NetworkLocation.
type PortResult ¶
type PortResult struct { // Open is a list ports that where determined as open. Open netUtil.Ports // Closed is a list of ports that where determined as closed. Closed netUtil.Ports // Filtered is a list of ports that where determined as filtered. Filtered netUtil.Ports }
PortResult represents the result of a port scan for every port of the target. The open, closed and filtered ports are contained in Open, Closed and Filtered respectively to the outcome of the scan.
func NewPortResult ¶
func NewPortResult() *PortResult
NewPortResult returns a pointer to an uninitialized instance of PortResult.
func (*PortResult) ColorString ¶
func (p *PortResult) ColorString() string
ColorString returns a colored string representation of the PortResult pointer.
func (*PortResult) CustomColorString ¶
func (p *PortResult) CustomColorString(showClosed bool) string
CustomColorString returns a colored string representation of the PortResult pointer. The parameter showClosed controls if closed and filtered ports also will be incorporated into the string.
func (*PortResult) String ¶
func (p *PortResult) String() string
String returns a string representation of the PortResult pointer.
type ScanResult ¶
type ScanResult struct { // StartTime is the time the scan was started at. StartTime time.Time // EndTime is the time the scan was finished at. EndTime time.Time // Target is the scan Target. Target *Target // Ports is the PortResult of the scan. Ports *PortResult }
ScanResult represents the result of a single port scan. It contains the scans StartTime and EndTime, the scan Target and the PortResult.
func NewScanResult ¶
func NewScanResult(t *Target, startTime time.Time) *ScanResult
NewScanResult returns the pointer to a new ScanResult instance. The parameter t is the Target of the scan and startTime is the start time.Time of the scan.
func (*ScanResult) ColorString ¶
func (s *ScanResult) ColorString() string
ColorString returns a colored string representation of the ScanResult pointer.
func (*ScanResult) CustomColorString ¶
func (s *ScanResult) CustomColorString(showClosed bool) string
CustomColorString returns a colored string representation of the ScanResult pointer. The parameter showClosed controls if closed and filtered ports also will be incorporated into the string.
func (*ScanResult) String ¶
func (s *ScanResult) String() string
String returns a string representation of the ScanResult pointer.
type Target ¶
type Target struct { // HostName is string containing the host name of the Target. HostName HostName //Vendor is a string containing the name of the Target vendor if the lookup was successful. Vendor string // IPAddr is the ip of the Target. IPAddr net.IP // MACAddr is the MAC-address of the target if it could be found. MACAddr net.HardwareAddr // InitialTarget is a string containing the initial IP-address or host name the target was created with. InitialTarget string // Status contains the TargetStatus Status TargetStatus // Location contains the NetworkLocation of the Target. Location NetworkLocation // Ports is a list of type netUtil.ports to be scanned. Ports netUtil.Ports // RTTs contains the round trip times of the ping requests if they could be send successfully. RTTs []time.Duration }
Target represent a network host with all the necessary fields to conduct a port scan. A target always should be initialized with the NewTarget, AsyncNewTarget or ParseHostString methods.
func NewTarget ¶
NewTarget returns a pointer to an initialized instance of Target as defined by the targetAddress and ports. Before returning the Target, it is resolved by calling Target.Resolve. If the resolve was successful, AsyncNewTarget will try to send a ping request by calling Target.Ping and to query the MAC-address and vendor name by calling Target.QueryMac and Target.LookUpVendor. scanLock is used to controls how many targets may be resolved simultaneously and privileged controls if the scan should be run either in a (more detailed) mode that require root privileges, or (in the less detailed) 'user' mode.
func (*Target) ColorString ¶
ColorString returns a colored string representation of the Target pointer.
func (*Target) IsHost ¶
IsHost returns true when the Target pointer is the host and false otherwise.
func (*Target) LookUpVendor ¶
func (t *Target) LookUpVendor()
LookUpVendor tries to perform a vendor lookup based on the MAC address of the Target pointer by sending a HTTP request to the vendor lookup API of 'macvendors.co'.
func (*Target) Ping ¶
Ping sends a ping request to the IP address of the Target pointer. count specifies how many requests should be send and privileged
func (*Target) QueryMac ¶
func (t *Target) QueryMac()
QueryMac tries to query the MAC address of the Target pointer either by ARP cache lookup or alternatively if not found in cache by sending an ARP-request.
func (*Target) Resolve ¶
func (t *Target) Resolve()
Resolve tries to resolve the IP address and the host name of the Target pointer.
func (*Target) Scan ¶
func (t *Target) Scan() *ScanResult
Scan performs a concurrent full connection scan for all ports of a singe Target and returns a pointer to the ScanResult when finished.
type TargetStatus ¶
type TargetStatus int
TargetStatus is an integer representing the status of the Target. The values can be Online, OfflineFiltered or Unknown.
func (TargetStatus) ColorString ¶
func (ts TargetStatus) ColorString() string
ColorString returns a colored string representation of TargetStatus.
func (TargetStatus) String ¶
func (ts TargetStatus) String() string
String returns a string representation of TargetStatus.
type Targets ¶
type Targets []*Target
Targets is an array of Target pointers.
func ParseHostString ¶
ParseHostString parses hosts and returns the initialized Targets.
hosts is comma separated list of values that can be in either of the following formats: - A single IP address: 192.88.99.1 - A range of IP addresses: 192.88.99-100.1-100 - A CIDR formatted IP address range: 192.88.99.1/24 - A host name: example.com
ports is a list of type ports that should be scanned for every host in hosts.
privileged controls if the targets should be resolved either in a (more detailed) mode that require root privileges or (in the less detailed) 'user' mode.
func (Targets) Scan ¶
func (t Targets) Scan() MultiScanResult
Scan performs a concurrent full connection scan for every Target in Targets and once finished, returns the scan result as an MultiScanResult.