Skip to content

Commit

Permalink
add: Detect live C-class networks
Browse files Browse the repository at this point in the history
eg: -ip 192.168.0.0/16,172.16.0.0/12,10.0.0.0/8 -netLive
  • Loading branch information
XinRoom committed Oct 11, 2022
1 parent 9f2c240 commit 1152e76
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ go build cmd/go-portScan.go
`.\go-portScan.exe -ip 1.1.1.1/30 [-p str] [-Pn] [-sT] [-sV] [-rate num] [-rateP num] [-timeout num(ms)]`

```
NAME:
NAME:
PortScan - A new cli application
USAGE:
Expand All @@ -187,16 +187,17 @@ COMMANDS:
GLOBAL OPTIONS:
--ip value target ip, eg: "1.1.1.1/30,1.1.1.1-1.1.1.2,1.1.1.1-2"
--iL value target ip file, eg: "ips.txt"
--port value, -p value eg: "top1000,5612,65120" (default: "top1000")
--port value, -p value eg: "top1000,5612,65120,-" (default: "top1000")
--Pn no ping probe (default: false)
--rateP value, --rp value concurrent num when ping probe each ip (default: 300)
--sT TCP-mode(support IPv4 and IPv6) (default: false)
--timeout value, --to value TCP-mode SYN-mode timeout. unit is ms. (default: 800)
--sS Use SYN-mode(Only IPv4) (default: true)
--dev value specified pcap dev name
--rate value, -r value number of packets sent per second. If set -1, TCP-mode is 1000, SYN-mode is 2000(SYN-mode is restricted by the network adapter, 2000=1M) (default: -1)
--rate value, -r value number of packets sent per second. If set -1, TCP-mode is 1000, SYN-mode is 2000(SYN-mode is restricted by the network adapter, 2000=1M) (default: -1)
--devices, --ld list devices name (default: false)
--sV port service identify (default: false)
--httpx http server identify (default: false)
--netLive Detect live C-class networks, eg: -ip 192.168.0.0/16,172.16.0.0/12,10.0.0.0/8 (default: false)
--help, -h show help (default: false)
```
45 changes: 45 additions & 0 deletions cmd/go-portScan.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/panjf2000/ants/v2"
"github.com/urfave/cli/v2"
"log"
"math/rand"
"net"
"os"
"strings"
Expand All @@ -33,6 +34,7 @@ var (
devices bool
dev string
httpx bool
netLive bool
)

func parseFlag(c *cli.Context) {
Expand All @@ -48,6 +50,7 @@ func parseFlag(c *cli.Context) {
sV = c.Bool("sV")
timeout = c.Int("timeout")
httpx = c.Bool("httpx")
netLive = c.Bool("netLive")
}

func run(c *cli.Context) error {
Expand Down Expand Up @@ -104,6 +107,43 @@ func run(c *cli.Context) error {
}
ipRangeGroup = append(ipRangeGroup, it)
}

// netLive
var wgIpsLive sync.WaitGroup
// Pool - ipsLive
poolIpsLive, _ := ants.NewPoolWithFunc(rateP, func(ip interface{}) {
_ip := ip.([]net.IP)
for _, ip2 := range _ip {
if host.IsLive(ip2.String()) {
fmt.Printf("[+] %s is live\n", ip2.String())
break
}
}
wgIpsLive.Done()
})
defer poolIpsLive.Release()

if netLive {
// 按c段探测
for _, ir := range ipRangeGroup { // ip group
for i := uint64(0); i < ir.TotalNum(); i = i + 256 { // ip index
ip := make(net.IP, len(ir.GetIpByIndex(0)))
copy(ip, ir.GetIpByIndex(i)) // Note: dup copy []byte when concurrent (GetIpByIndex not to do dup copy)
ipLastByte := []byte{1, 2, 254, 253, byte(100 + rand.Intn(20)), byte(200 + rand.Intn(20))}
ips2 := make([]net.IP, 6)
for j := 0; j < 6; j++ {
ips2[j] = make(net.IP, len(ip))
ip[3] = ipLastByte[j]
copy(ips2[j], ip)
}
wgIpsLive.Add(1)
poolIpsLive.Invoke(ips2)
}
}
wgIpsLive.Wait()
return nil
}

// port parse
ports, err := port.ShuffleParseAndMergeTopPorts(portStr)
if err != nil {
Expand Down Expand Up @@ -346,6 +386,11 @@ func main() {
Usage: "http server identify",
Value: false,
},
&cli.BoolFlag{
Name: "netLive",
Usage: "Detect live C-class networks, eg: -ip 192.168.0.0/16,172.16.0.0/12,10.0.0.0/8",
Value: false,
},
},
}

Expand Down

0 comments on commit 1152e76

Please sign in to comment.