From 963b809e525ae6383aad71fe29808b7abb445cb3 Mon Sep 17 00:00:00 2001 From: Emile Date: Thu, 27 Jun 2019 01:23:55 +0200 Subject: added the -stdin flag, doing exactly what it says --- stdin-service/main.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'stdin-service/main.go') diff --git a/stdin-service/main.go b/stdin-service/main.go index 39843a1..df0c503 100644 --- a/stdin-service/main.go +++ b/stdin-service/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "io/ioutil" + "io" "log" "os" "net" @@ -14,25 +15,35 @@ var ( host = flag.String("h", "localhost", "the host to pee against") port = flag.Int("p", 1337, "the port to use") protocol = flag.String("protocol", "tcp", "the protocol to use") + stdin = flag.Bool("stdin", false, "read from stdin") ) func main() { flag.Parse() - dat, err := ioutil.ReadFile(*inputFile) - if err != nil { - log.Printf("Error reading file: %v", err) - os.Exit(1) - } - - conn, _ := net.Dial(*protocol, fmt.Sprintf("%s:%d", *host, *port)) + var dat []byte - writtenBytes, err := conn.Write(dat) - if err != nil { - log.Printf("Error accepting: %v", err) + if !*stdin { + var ReadFileErr error + dat, ReadFileErr = ioutil.ReadFile(*inputFile) + if ReadFileErr != nil { + log.Printf("Error reading file: %v", ReadFileErr) os.Exit(1) + } + } else { + dat = make([]byte, 1000) + _, err := io.ReadFull(os.Stdin, dat) + if err != nil { + log.Printf("Error reading from stdin: %v", err) + } } - fmt.Printf("Written %d bytes", writtenBytes) + conn, _ := net.Dial(*protocol, fmt.Sprintf("%s:%d", *host, *port)) + writtenBytes, err := conn.Write(dat) + if err != nil { + log.Printf("Error accepting: %v", err) + os.Exit(1) + } + fmt.Printf("Written %d bytes", writtenBytes) } -- cgit 1.4.1