Skip to content

Commit

Permalink
[+]新增全局异常捕获,现在不会出现因为一个协程而导致程序崩溃的情况了。
Browse files Browse the repository at this point in the history
  • Loading branch information
lcvvvv committed May 7, 2021
1 parent 8b19b96 commit ccc0e6c
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions gonmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,20 @@ func (n *Nmap) SafeScan(ip string, port int, timeout time.Duration) *PortInfomat
}

func (n *Nmap) safeScanSub(ip string, port int, ctx context.Context, resChan chan *PortInfomation) {
r := n.Scan(ip, port)
resChan <- r
ctx.Done()
isDone := make(chan int)
go func() {
defer func() {
if err := recover(); err != nil {
//log.E(this.Ctx, "Skip panic", "tmpInfo=[%+v]", tmpInfo)
//Skip panic
}
isDone <- 1
}()
r := n.Scan(ip, port)
resChan <- r
ctx.Done()
}()
<-isDone
}

func (n *Nmap) Scan(ip string, port int) *PortInfomation {
Expand Down

0 comments on commit ccc0e6c

Please sign in to comment.