GoScan

package module
v0.1.24 Latest Latest
Warning

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

Go to latest
Published: May 8, 2023 License: MIT Imports: 9 Imported by: 0

README

GoScan

GoScan is a blanzingly fast network/port scanner written in Go.

Installation

⚠️ NOTE: This module is under heavy development. If any errors occur please file an issue. Move to your folder containing your go.mod and type:

go get github.com/menaruben/GoScan

Future features

If you have ideas what could be added to this go module please let me now and file an issue with your idea and examples of the usage.

Documentation / Examples

Please visit the pkg.go.dev for documentation and examples on how to use this module.

License

MIT License

Copyright (c) 2023 Rubén Mena

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Documentation

Overview

Package GoScan is a blanzingly fast network/port scanner written in Go

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetService added in v0.1.8

func GetService(port int) string

The GetService returns the service for the given port.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
)

func main() {
	service := GoScan.GetService(22)
	fmt.Println(service)
}
Output:

SSH (Secure Shell)

func GetSubnetMask added in v0.1.8

func GetSubnetMask(suffix int) string

GetSubnetMask returns the subnet mask in the x.x.x.x format and takes the subnet suffix as input.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
)

func main() {
	subnetMask := GoScan.GetSubnetMask(25)
	fmt.Println(subnetMask)
}
Output:

255.255.255.128

func IsIPReachable added in v0.1.10

func IsIPReachable(ipAddr string, timeout time.Duration) (bool, error)

IsIPReachable returns if an IP address is reachable

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	validCheck, err := GoScan.IsIPReachable("142.250.203.100", 12*time.Second)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(validCheck)
}
Output:

true

func ResultOutput

func ResultOutput(results []ScanResult)

ResultOutput prints the output to the terminal as a table.

Example
package main

import (
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	// scan ports 20 to 30
	portRange := [2]int{20, 30}

	// scan ports concurrently
	result := GoScan.ScanHostFast("localhost", portRange, 12*time.Second)
	GoScan.ResultOutput(result)
}
Output:

+------+-------+--------------------+
| PORT | STATE |      SERVICE       |
+------+-------+--------------------+
|   22 | open  | SSH (Secure Shell) |
+------+-------+--------------------+

func ScanNetHosts added in v0.1.15

func ScanNetHosts(network NetworkInfo, portRange [2]int, scanInterval time.Duration, timeout time.Duration) ([][2]any, []error)

ScanNetHosts returns an array of an array of scan results of all hosts inside a network

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	portRange := [2]int{20, 30}
	myNetwork, _ := GoScan.ScanNetwork("192.168.1.0/24", 12*time.Second)
	myResult, err := GoScan.ScanNetHosts(myNetwork, portRange, 0*time.Second, 12*time.Second)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(myResult)
}
Output:

[[192.168.1.74 []] [192.168.1.19 [{22 true}]]

func ScanNetHostsFast added in v0.1.15

func ScanNetHostsFast(network NetworkInfo, portRange [2]int, timeout time.Duration) [][2]any

ScanNetHostsFast returns an array of an array of scan results of all hosts inside a network

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	portRange := [2]int{20, 30}
	myNetwork, err := GoScan.ScanNetwork("192.168.1.0/24", 12*time.Second)
	if err != nil {
		fmt.Println(err)
	}

	myResult := GoScan.ScanNetHostsFast(myNetwork, portRange, 12*time.Second)

	fmt.Println(myResult)
}
Output:

[[192.168.1.19 [{22 true}]] [192.168.1.74 []]

func ValidateIpv4 added in v0.1.8

func ValidateIpv4(ipaddr string) (bool, error)

ValidateIpv4 returns a bool and checks wether the input is a valid IPv4 address.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
)

func main() {
	validCheck, err := GoScan.ValidateIpv4("192.168.100.29")
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(validCheck)
}
Output:

true

Types

type NetworkInfo added in v0.1.10

type NetworkInfo struct {
	NetworkIP    string
	SubnetMask   string
	SubnetSuffix int
	Hosts        []string
}

NetworkInfo contains information about a network.

func ScanNetwork added in v0.1.10

func ScanNetwork(netaddr string, timeout time.Duration) (NetworkInfo, error)

ScanNetwork returns NetworkInfo about a specific network. It contains the network IP, subnet mask/suffix and all hosts.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	myNetwork, err := GoScan.ScanNetwork("192.168.1.0/24", 12*time.Second)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(myNetwork)
}
Output:

{192.168.1.0 255.255.255.0 24 [192.168.1.19 192.168.1.4 192.168.1.101]}

type ScanResult

type ScanResult struct {
	Port  int
	State bool
}

ScanResult struct contains the port and its state as a boolean (open = true, closed = false).

func ScanHost

func ScanHost(hostname string, portRange [2]int, scanInterval time.Duration, timeout time.Duration) ([]ScanResult, error)

ScanHost scans all ports inside the portRange argument and returns all open ports.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	// scan ports 20 to 30
	portRange := [2]int{20, 30}

	// scan each port with 2 seconds interval
	result, err := GoScan.ScanHost("localhost", portRange, 2*time.Second, 12*time.Second)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(result)
}
Output:

Port scanning finished in 45.630600 seconds
[{22 true}]

func ScanHostFast

func ScanHostFast(hostname string, portRange [2]int, timeout time.Duration) []ScanResult

ScanHostFast scans all ports inside the portRange argument concurrently and returns all open ports.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	// scan ports 20 to 30
	portRange := [2]int{20, 30}

	// scan ports concurrently
	result := GoScan.ScanHostFast("localhost", portRange, 12*time.Second)
	fmt.Println(result)
}
Output:

[{22 true}]

func ScanPort

func ScanPort(hostname string, port int, timeout time.Duration) (ScanResult, error)

ScanPort scans a single port.

Example
package main

import (
	"fmt"
	GoScan "github.com/menaruben/GoScan"
	"time"
)

func main() {
	sshResult, err := GoScan.ScanPort("localhost", 22, 12*time.Second)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(sshResult.Port, sshResult.State)
}
Output:

22 true

Jump to

Keyboard shortcuts

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