portscanner

package module
v0.0.0-...-2fa2283 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Unlicense Imports: 8 Imported by: 0

README

Codacy Badge Build Status Coverage Status

Go-Portscanner

TCP Network Port Scanner written in Go, nmap style.

Lib

Usage examples
Scan specific ports from an IP address
package main

// imports fmt lib and portscanner lib.
import "fmt"
import "github.com/ivopetiz/portscanner"

// Main function.
func main() {

	// ports is an slice of strings corresponding to ports we want
	// to scan.
	ports := []string{"21", "22", "80"}

	// ip_t is a slice of strings containing an IP address.
	ip_t := []string{"192.168.1.100"}

	// open_ports has the results from PortScanner.
	open_ports := portscanner.PortScanner(ip, ports)

	fmt.Println(open_ports)
}
Scan port 80 in a range of IP addresses
package main

// imports fmt lib and portscanner lib.
import "github.com/ivopetiz/portscanner"

// Main function.
func main() {
	
	// ports is a slice of ports to test.
	ports := []string{"80"}

	// IP sequence is defined by a '-' between first and last IP address .
	ips_sequence := []string{"192.168.1.1-254"}

	// results returns a map with open ports for each IP address.
	results := portscanner.IPScanner(ips_list, ports, true)
	// Once IPScanner has true for print_results, lib will present
	// results in CL with a nice presentation.
}

App

Installation
 go install https://github.com/ivopetiz/portscanner
 git clone https://github.com/ivopetiz/portscanner.git portscanner
 cd portscanner
 go build cmd/portscanner/portscanner.go

Usage examples

Different ways to use Go-Portscanner.

Get help
 portscanner -h
 Usage of portscanner:
   -A   Scans all ports from port 1 to 1024
   -p   Port or ports to scan (default "80")

Shows the output above, presenting the available options.

Localhost Portscanner
$ portscanner

Scans all local machine ports, from 1 to 1024.

Network Machine Full Port Scan
$ portscanner -p 1-65535 210.67.210.76

Scan all TCP ports from a network machine.

Network Discovery
$ portscanner -p 21,80 192.168.0.1-192.168.0.254

Looks for HTTP and FTP servers on 192.168.0.0/24.

Ping Servers
$ portscanner -p 22 113.213.200.101 4.0.75.4 84.188.238.94 11.2.224.214 153.194.246.247

Checks if SSH servers are up.

TODO

  • Improve performance.
  • Improve presentation.
  • Read IP:Port pair from file.
  • Tests
  • Docker

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(err error)

Check checks if an error is nil or a significant error.

func IPScanner

func IPScanner(ipstr []string, portStr []string, printResults bool) map[IPv4][]string

IPScanner scans all IP addresses in ipList for every port in portList.

func ParsePortList

func ParsePortList(rawPorts string) []string

ParsePortList gets a port list from its port entry in arguments.

func PortScanner

func PortScanner(ip IPv4, portList []string) []string

PortScanner scans IP:port pairs looking for open ports on IP addresses.

func PresentResults

func PresentResults(ip IPv4, ports []string) int

PresentResults presents all results in console.

func ToInt

func ToInt(s string) int

ToInt converts a string to integer, as strconv.Atoi does, but without returning errors.

Types

type IPv4

type IPv4 [4]int

IPv4 is the type used for IP addresses.

func ParseIPSequence

func ParseIPSequence(ipSequence string) []IPv4

ParseIPSequence gets a sequence of IP addresses correspondent from an "init-end" entry.

func ToIPv4

func ToIPv4(ip string) IPv4

ToIPv4 converts an string to a IPv4.

func (*IPv4) IsValid

func (ip *IPv4) IsValid() bool

IsValid checks an IP address as valid or not.

func (*IPv4) PlusPlus

func (ip *IPv4) PlusPlus() *IPv4

PlusPlus increments an IPv4 value.

func (*IPv4) ToString

func (ip *IPv4) ToString() string

ToString converts an IP from IPv4 type to string.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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