代码拉取完成,页面将自动刷新
package main
import (
"flag"
"fmt"
"net"
"sync"
"time"
)
func main() {
ip := flag.String("ip", "", "scan ip")
start := flag.Int("start", 0, "port scope start")
end := flag.Int("end", 0, "port scope end")
timeout := flag.Int("timeout", 1, "port scope timeout, default 1s")
flag.Parse()
filter(*ip, *start, *end, *timeout)
}
func filter(ip string, start int, end int, timeout int) {
port := 0
if ip == "" {
fmt.Printf("%s ip为空\n", ip)
return
}
if timeout <= 0 {
fmt.Printf("%d 超时时间不能设置为负数或0\n", timeout)
return
}
if start != 0 && end == 0 {
port = start
handleScan(ip, start, end, port, timeout)
return
}
if start < end {
//并行执行,加快速度
var wg sync.WaitGroup
for i := start; i < end; i++ {
wg.Add(1)
go func(j int) {
defer wg.Done()
handleScan(ip, start, end, j, timeout)
}(i)
}
wg.Wait()
}
}
func handleScan(ip string, start int, end int, port int, timeout int) {
address := fmt.Sprintf("%s:%d", ip, port)
_, err := net.DialTimeout("tcp", address, time.Duration(timeout)*time.Second)
if err == nil {
fmt.Printf("scan result: %s\tsuccess\n", address)
} else {
fmt.Printf("scan result: %s\tbe rejected\n", address)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。