繁体   English   中英

Golang中的缓冲区问题

[英]Buffer Issue in Golang

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

只要我调用名为nmap的函数,我的代码就会像预期的那样工作。 调用nmap ,它退出并显示以下错误:

./recon-s.go:54:12:调用nmap的参数不足,缺少()个(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()
}

您得到的错误是:

调用nmap的参数不足,需要()个(chan <-[] byte)

这意味着main方法中的nmap()没有任何参数,但是实际的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()
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM