猿问

Golang 中的缓冲区问题

我正在处理多线程和序列化流程,并希望自动化我的侦察流程。


只要我不调用名为nmap. 调用时nmap,它退出并出现以下错误:


./recon-s.go:54:12: 调用 nmap 时参数不足 () want (chan<- []byte)


这是我的代码:


package main


import (

    "fmt"

    "log"

    "os/exec"

    "sync"

)


var url string

var wg sync.WaitGroup

var ip string

func 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()

}


弑天下
浏览 91回答 1
1回答

达令说

你得到的错误是:调用 nmap 时参数不足 have () want (chan<- []byte)这意味着nmap()方法main没有任何参数,但实际nmap()定义需要一个参数chan<-[]byte,所以你必须从nmap()下面传递一个参数,我提到了你刚刚错过的参数。&nbsp; func main() {&nbsp; &nbsp; &nbsp; &nbsp; outChan := make(chan []byte)&nbsp; &nbsp; &nbsp; &nbsp; fmt.Printf("Please input URL")&nbsp; &nbsp; &nbsp; &nbsp; fmt.Scanln(&url)&nbsp; &nbsp; &nbsp; &nbsp; wg.Add(1)&nbsp; &nbsp; &nbsp; &nbsp; go nikto(outChan)&nbsp; &nbsp; &nbsp; &nbsp; wg.Add(1)&nbsp; &nbsp; &nbsp; &nbsp; go whois(outChan)&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; wg.Add(1)&nbsp; &nbsp; &nbsp; &nbsp; go nmap(outChan) //you are just missing the argument here.&nbsp; &nbsp; &nbsp; &nbsp; for i := 0; i < 3; i++ {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bs := <-outChan&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fmt.Println(string(bs))&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; close(outChan)&nbsp; &nbsp; &nbsp; &nbsp; wg.Wait()&nbsp; &nbsp; }
随时随地看视频慕课网APP

相关分类

Go
我要回答