为了账号安全,请及时绑定邮箱和手机立即绑定

Golang 中的缓冲区问题

Golang 中的缓冲区问题

Go
弑天下 2023-04-10 10:31:39
我正在处理多线程和序列化流程,并希望自动化我的侦察流程。只要我不调用名为nmap. 调用时nmap,它退出并出现以下错误:./recon-s.go:54:12: 调用 nmap 时参数不足 () want (chan<- []byte)这是我的代码:package mainimport (    "fmt"    "log"    "os/exec"    "sync")var url stringvar wg sync.WaitGroupvar ip stringfunc nikto(outChan chan<- []byte) {    cmd := exec.Command("nikto", "-h", url)    bs, err := cmd.Output()    if err != nil {        log.Fatal(err)    }    outChan <- bs    wg.Done()}func whois(outChan chan<- []byte) {    cmd := exec.Command("whois",url)    bs, err := cmd.Output()    if err != nil {        log.Fatal(err)    }    outChan <- bs    wg.Done()}func nmap (outChan chan<-[]byte) {    fmt.Printf("Please input IP")    fmt.Scanln(&ip)    cmd := exec.Command("nmap","-sC","-sV","-oA","nmap",ip)    bs,err := cmd.Output()    if err != nil {    log.Fatal(err)    }    outChan <- bs    wg.Done()    }func main() {    outChan := make(chan []byte)    fmt.Printf("Please input URL")    fmt.Scanln(&url)    wg.Add(1)    go nikto(outChan)    wg.Add(1)    go whois(outChan)    wg.Add(1)    go nmap()    for i := 0; i < 3; i++ {        bs := <-outChan        fmt.Println(string(bs))    }    close(outChan)    wg.Wait()}
查看完整描述

1 回答

?
达令说

TA贡献1821条经验 获得超6个赞

你得到的错误是:


调用 nmap 时参数不足 have () want (chan<- []byte)


这意味着nmap()方法main没有任何参数,但实际nmap()定义需要一个参数chan<-[]byte,所以你必须从nmap()下面传递一个参数,我提到了你刚刚错过的参数。


  func main() {

        outChan := make(chan []byte)


        fmt.Printf("Please input URL")

        fmt.Scanln(&url)

        wg.Add(1)

        go nikto(outChan)

        wg.Add(1)

        go whois(outChan) 

        wg.Add(1)

        go nmap(outChan) //you are just missing the argument here.

        for i := 0; i < 3; i++ {

            bs := <-outChan

            fmt.Println(string(bs))

        }


        close(outChan)

        wg.Wait()

    }


查看完整回答
反对 回复 2023-04-10
  • 1 回答
  • 0 关注
  • 70 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信