scanner

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2020 License: MIT Imports: 22 Imported by: 0

README

fast-scanner

Build Status Go Report Card GoDoc license
fast-scanner can make it easy for you to develop scanners

Features

  • Support CONNECT & SYN method
  • SYN scanning method is similar to masscan stateless scanning
  • Support IPv4 & IPv6
  • Support Windows & Linux
  • Scan result is a string channal

Dependence

windows: 
  Winpcap or Npcap
linux:
  apt-get libpcap-dev
  yum install libpcap-devel

Install

wget https://github.com/For-ACGN/fast-scanner/install.sh
chmod +x install.sh && ./install.sh

Parameter

targets:
  "1.1.1.1, 1.1.1.2-1.1.1.3, 1.1.1.1/24"
  "2606:4700:4700::1001, 2606:4700:4700::1002-2606:4700:4700::1003"
ports:
  "80, 81-82"
Options:
  see options.go

Example

s, err := scanner.New("1.1.1.1-1.1.1.2, 2606:4700:4700::1001", "53-54", nil)
if err != nil {
    log.Fatalln(err)
}
err = s.Start()
if err != nil {
    log.Fatalln(err)
}
for address := range s.Result {
    log.Print(address + "\r\n")
}
1.1.1.1:53
[2606:4700:4700::1001]:53

TODO

1. target support IPv6 CIDR
2. BPFFilter for IPv6
     _ = handle.SetBPFFilter("tcp[13] = 0x12")
     is not support IPv6
3. PF_RING

Documentation

Index

Examples

Constants

View Source
const (
	MethodSYN     = "syn"
	MethodConnect = "connect"
)

Variables

View Source
var ErrNoInterfaces = errors.New("no Interfaces")

Functions

This section is empty.

Types

type Dialer

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

func NewDialer

func NewDialer(localIPs []string, timeout time.Duration) (*Dialer, error)

func (*Dialer) Dial

func (d *Dialer) Dial(network, address string) (net.Conn, error)

type Generator

type Generator struct {
	N  *big.Int // host number will be generate
	IP chan net.IP
	// contains filtered or unexported fields
}
Example
testdata := [][]string{
	{"192.168.1.1"},
	{"192.168.1.1-192.168.1.1"},
	{"192.168.1.1-192.168.1.3"},
	{"192.168.1.1/31"},
	{"fe80::1"},
	{"fe80::1-fe80::1"},
	{"fe80::1-fe80::2"},
	{"::1-::2"},
}
for _, targets := range testdata {
	generator, err := NewGenerator(targets)
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println("number:", generator.N)
	for ip := range generator.IP {
		fmt.Println(ip, len(ip))
	}
}

// check number
l := len(testdata)
targets := make([]string, l)
for i := 0; i < l; i++ {
	targets[i] = testdata[i][0]
}
generator, err := NewGenerator(targets)
if err != nil {
	log.Fatalln(err)
}
generator.Close()
fmt.Println("number:", generator.N)
Output:

number: 1
192.168.1.1 4
number: 1
192.168.1.1 4
number: 3
192.168.1.1 4
192.168.1.2 4
192.168.1.3 4
number: 2
192.168.1.0 4
192.168.1.1 4
number: 1
fe80::1 16
number: 1
fe80::1 16
number: 2
fe80::1 16
fe80::2 16
number: 2
::1 16
::2 16
number: 13

func NewGenerator

func NewGenerator(targets []string) (*Generator, error)

func (*Generator) Close

func (g *Generator) Close()

type Interface

type Interface struct {
	Name     string // windows: "Ethernet0"          linux: "eth0"
	Device   string // windows: "\Device\NPF_{GUID}" linux: "eth0"
	MAC      net.HardwareAddr
	IPNets   []*net.IPNet
	Gateways []net.IP
}

func GetAllInterfaces

func GetAllInterfaces() ([]*Interface, error)

func SelectInterface

func SelectInterface(name string) (*Interface, error)

if name is "" select the first interface

type Options

type Options struct {
	// "syn", "connect"
	Method  string
	Device  string
	Rate    int
	Timeout time.Duration
	// "connect": connectScanner() goroutine number
	// "syn": synScanner() and synParser() goroutine number
	Workers int
	// packetSender number useless for "connect"
	Senders int
	// if true scanner will not handle duplicate result,
	// it will use less memory
	// default will handle duplicate result
	Raw bool
}

type Scanner

type Scanner struct {

	// about scanning
	Result chan string
	// contains filtered or unexported fields
}

func New

func New(targets, ports string, opts *Options) (*Scanner, error)

func (*Scanner) HostNum

func (s *Scanner) HostNum() *big.Int

func (*Scanner) Scanned

func (s *Scanner) Scanned() *big.Int

func (*Scanner) Start

func (s *Scanner) Start() error

func (*Scanner) Stop

func (s *Scanner) Stop()

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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