duanliang1999 2018-09-22 11:30
浏览 64
已采纳

Golang中的缓冲区问题

I'm working with multi-threaded and serialized processes and want to automate my recon process.

My code works like expected, as long as i'm not calling a function called nmap. When nmap is called, it exits with the following error:

./recon-s.go:54:12: not enough arguments in call to nmap have () want (chan<- []byte)

This is my code:

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()
}
  • 写回答

1条回答 默认 最新

  • dongsou0083 2018-09-22 12:07
    关注

    The error which one you're getting is:

    not enough arguments in call to nmap have () want (chan<- []byte)

    It means nmap() from main method have not any argument but the actual nmap() definition want an argument like chan<-[]byte, So you have to pass an argument from nmap() like below I mentioned the argument which one you just missed.

      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()
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大