Created
August 13, 2018 20:12
-
-
Save bgrewell/ecd38d32ccd6bb980d6c116df1cbe6f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net" | |
"fmt" | |
"math/rand" | |
"flag" | |
"bufio" | |
"os" | |
"strconv" | |
) | |
func getUsage() (usage func()) { | |
return func() { | |
usageLineFormat := " %-15s %-7v %s\n" | |
fmt.Println("[+] NetFill Usage") | |
fmt.Printf(usageLineFormat, "Parameter", "Default", "Description") | |
fmt.Printf(usageLineFormat, "-t", "-", "target address to send packets") | |
fmt.Printf(usageLineFormat, "-l", "8000", "size of packets to send") | |
fmt.Printf(usageLineFormat, "-P", "1", "number of parallel threads to run") | |
} | |
} | |
func StartSender(proto, host, port string, bufflen int) { | |
fmt.Println("Starting sender...") | |
connection, _ := net.Dial(proto, host + ":" + port) | |
buffer := make([]byte, bufflen) // Set to packet size | |
rand.Read(buffer) | |
for { | |
connection.Write(buffer) | |
} | |
} | |
func StartReceiver(proto, port string, bufflen int) { | |
fmt.Println("Starting receiver...") | |
listener, _ := net.Listen(proto, ":"+port) | |
connection, _ := listener.Accept() | |
buffer := make([]byte, bufflen) // Should be set to payload size... | |
var counter uint64 | |
for { | |
numRead, _ := connection.Read(buffer) | |
counter += uint64(numRead) | |
} | |
} | |
func main() { | |
flag.Usage = getUsage() | |
basePort := 9000 | |
target := flag.String("t", "", "target address to send packets") | |
bufflen := flag.Int("l", 8000, "size of packets to send") | |
threads := flag.Int("P", 1, "number of parallel threads to run") | |
for i := 0; i < *threads; i++ { | |
go StartReceiver("tcp", strconv.Itoa(basePort + i), *bufflen) | |
} | |
reader := bufio.NewReader(os.Stdin) | |
fmt.Print("Once both sides are started press enter to start sending: ") | |
reader.ReadString('\n') | |
for i := 0; i < *threads -1; i++ { | |
go StartSender("tcp", *target, strconv.Itoa(basePort + 1), *bufflen) | |
} | |
StartSender("tcp", *target, strconv.Itoa(basePort + *threads -1), *bufflen) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment