我是小葵
Toggle navigation
Home
Archives
Tags
Black Hat Go 之 端口扫描
2022-11-28 09:06:58
9
0
0
admin
package main import( "fmt" "net" "sync" ) func main(){ var wg sync.WaitGroup for i := 1; i <= 1024; i++{ wg.Add(1) go func(j int) { defer wg.Done() address := fmt.Sprintf("xiaokv.com:%d",j) conn,err := net.Dial("tcp",address) if err != nil{ return } conn.Close() fmt.Printf("%d open\n",j) }(i) #go func 闭包函数最后的参数 } wg.Wait() } 结果: PS D:\pentest\漏扫> go run .\portscan.go 443 open 22 open 如果增加一句打印当前检测端口,就会看到这样的结果 fmt.Printf("test %d\n",j) PS D:\pentest\漏扫> go run .\portscan.go test 2 test 46 test 49 test 44 test 129 test 10 test 11 test 12 test 16 test 14 test 15 test 17 test 169 test 19 test 20 test 196 test 22 test 226 可见go的协程启动了。 通过worker pool的方式来做。 package main import( "fmt" "sync" ) func worker(ports chan int,wg *sync.WaitGroup){ for p := range ports { fmt.Println(p) wg.Done() } } func main(){ ports := make(chan int, 100) var wg sync.WaitGroup for i:= 0;i<=cap(ports);i++{ go worker(ports,&wg) } for i:=1;i<1024;i++{ wg.Add(1) ports <- i } wg.Wait() close(ports) }
Pre:
Black Hat Go之proxy
Next:
ceph-objectstore-tool工具使用详解
0
likes
9
Weibo
Wechat
Tencent Weibo
QQ Zone
RenRen
Table of content