about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEmile <hanemile@protonmail.com>2019-06-27 01:23:55 +0200
committerEmile <hanemile@protonmail.com>2019-06-27 01:23:55 +0200
commit963b809e525ae6383aad71fe29808b7abb445cb3 (patch)
tree53aadac2a8c2c590fd170a9e916092482ef75882
parentcc935e2535ff65dfe88ddaa43dded7816179ee49 (diff)
added the -stdin flag, doing exactly what it says
-rw-r--r--stdin-service/default.txt1
-rw-r--r--stdin-service/main.go33
2 files changed, 22 insertions, 12 deletions
diff --git a/stdin-service/default.txt b/stdin-service/default.txt
index 78ed276..7518f53 100644
--- a/stdin-service/default.txt
+++ b/stdin-service/default.txt
@@ -998,4 +998,3 @@
 997
 998
 999
-
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)
 }