添加功能,跳过某些ip扫描,-hn 192.168.1.1/24

This commit is contained in:
影舞者 2021-09-14 12:16:01 +08:00
parent 37f53e3f16
commit dc267a5335
5 changed files with 51 additions and 28 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"github.com/shadow1ng/fscan/common"
"net"
"sort"
"strconv"
"sync"
"time"
@ -19,22 +20,21 @@ func PortScan(hostslist []string, ports string, timeout int64) []string {
probePorts := common.ParsePort(ports)
noPorts := common.ParsePort(common.NoPorts)
if len(noPorts) > 0 {
var tmpPorts []int
temp := map[int]struct{}{}
for _, port := range probePorts {
var flag bool
nport:
for _, noport := range noPorts {
if port == noport {
flag = true
break nport
}
}
if flag {
continue
}
tmpPorts = append(tmpPorts, port)
temp[port] = struct{}{}
}
probePorts = tmpPorts
for _, port := range noPorts {
delete(temp, port)
}
var newDatas []int
for port, _ := range temp {
newDatas = append(newDatas, port)
}
probePorts = newDatas
sort.Ints(probePorts)
}
workers := common.Threads
Addrs := make(chan Addr, len(hostslist)*len(probePorts))

View File

@ -7,6 +7,7 @@ import (
"net"
"os"
"regexp"
"sort"
"strconv"
"strings"
)
@ -21,35 +22,54 @@ var ParseIPErr = errors.New(" host parsing error\n" +
"192.168.1.1-192.168.255.255\n" +
"192.168.1.1-255")
func ParseIP(ip string, filename string) (hosts []string, err error) {
func ParseIP(ip string, filename string, nohost string) (hosts []string, err error) {
if ip != "" {
hosts, err = ParseIPs(ip)
hosts = ParseIPs(ip)
}
if filename != "" {
var filehost []string
filehost, _ = Readipfile(filename)
hosts = append(hosts, filehost...)
}
if nohost != "" {
nohosts := ParseIPs(nohost)
if len(nohosts) > 0 {
temp := map[string]struct{}{}
for _, host := range hosts {
temp[host] = struct{}{}
}
for _, host := range nohosts {
delete(temp, host)
}
var newDatas []string
for host, _ := range temp {
newDatas = append(newDatas, host)
}
hosts = newDatas
sort.Strings(hosts)
}
}
hosts = RemoveDuplicate(hosts)
return hosts, err
}
func ParseIPs(ip string) (hosts []string, err error) {
func ParseIPs(ip string) (hosts []string) {
var err error
if strings.Contains(ip, ",") {
IPList := strings.Split(ip, ",")
var ips []string
for _, ip := range IPList {
ips, err = ParseIPone(ip)
CheckErr(ip, err)
hosts = append(hosts, ips...)
}
return hosts, err
} else {
hosts, err = ParseIPone(ip)
CheckErr(ip, err)
return hosts, err
}
CheckErr(ip, err)
return hosts
}
func ParseIPone(ip string) ([]string, error) {
@ -189,8 +209,7 @@ func Readipfile(filename string) ([]string, error) {
for scanner.Scan() {
text := strings.TrimSpace(scanner.Text())
if text != "" {
host, err := ParseIPs(text)
CheckErr(text, err)
host := ParseIPs(text)
content = append(content, host...)
}
}
@ -198,7 +217,7 @@ func Readipfile(filename string) ([]string, error) {
}
func RemoveDuplicate(old []string) []string {
result := make([]string, 0, len(old))
result := []string{}
temp := map[string]struct{}{}
for _, item := range old {
if _, ok := temp[item]; !ok {

View File

@ -5,8 +5,10 @@ import (
"strings"
)
func ParsePort(ports string) []int {
var scanPorts []int
func ParsePort(ports string) (scanPorts []int) {
if ports == "" {
return
}
slices := strings.Split(ports, ",")
for _, port := range slices {
port = strings.Trim(port, " ")
@ -39,7 +41,7 @@ func ParsePort(ports string) []int {
}
func removeDuplicate(old []int) []int {
result := make([]int, 0, len(old))
result := []int{}
temp := map[int]struct{}{}
for _, item := range old {
if _, ok := temp[item]; !ok {

View File

@ -92,5 +92,6 @@ var (
UrlFile string
Urls []string
NoPorts string
NoHosts string
SC string
)

View File

@ -19,6 +19,7 @@ func Banner() {
func Flag(Info *HostInfo) {
Banner()
flag.StringVar(&Info.Host, "h", "", "IP address of the host you want to scan,for example: 192.168.11.11 | 192.168.11.11-255 | 192.168.11.11,192.168.11.12")
flag.StringVar(&NoHosts, "hn", "", "the hosts no scan,as: -hn 192.168.1.1/24")
flag.StringVar(&Info.Ports, "p", DefaultPorts, "Select a port,for example: 22 | 1-65535 | 22,80,3306")
flag.StringVar(&NoPorts, "pn", "", "the ports no scan,as: -pn 445")
flag.StringVar(&Info.Command, "c", "", "exec command (ssh)")