Skip to content

Commit 792d446

Browse files
committed
Added progressbar for linescanner, improved performance for linescanner, moar pews
1 parent 21a8627 commit 792d446

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

main.go

+25-11
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ package main
22

33
import (
44
"bufio"
5+
"bytes"
56
"crypto/tls"
67
"encoding/json"
78
"flag"
89
"fmt"
10+
"io"
911
"log"
1012
"math/rand"
1113
"net"
@@ -57,7 +59,7 @@ func main() {
5759
maxstrategy := flag.String("maxstrategy", "fastest", "How to select servers if more are found than wanted (fastest, random)")
5860
parallel := flag.Int("parallel", 8, "How many connections per server to run in parallel")
5961

60-
log.Println("LDAP Nom Nom - anonymously bruteforce your way to Active Directory usernames")
62+
log.Println("LDAP Nom Nom - quietly and anonymously bruteforce your way to Active Directory usernames")
6163

6264
flag.Parse()
6365

@@ -75,9 +77,8 @@ func main() {
7577
}
7678
defer output.Close()
7779

78-
var pb *progressbar.ProgressBar
79-
input := os.Stdin
8080
var pbmax int
81+
input := os.Stdin
8182
if *inputname != "" {
8283
input, err = os.Open(*inputname)
8384
if err != nil {
@@ -87,14 +88,26 @@ func main() {
8788

8889
if *outputname != "" {
8990
// Count lines
90-
linescanner := bufio.NewScanner(input)
91-
linescanner.Split(bufio.ScanLines)
92-
var lines int
93-
for linescanner.Scan() {
94-
lines++
91+
stat, _ := input.Stat()
92+
pb := progressbar.DefaultBytes(stat.Size())
93+
pb.Describe("Counting lines")
94+
buf := make([]byte, 128*1024)
95+
lineSep := []byte{'\n'}
96+
br := bufio.NewReaderSize(input, 16*1024*1024)
97+
for {
98+
c, err := br.Read(buf)
99+
pbmax += bytes.Count(buf[:c], lineSep)
100+
pb.Add(c)
101+
102+
if err == io.EOF {
103+
break
104+
}
105+
if err != nil {
106+
log.Fatalf("failed to read from input file: %s", err)
107+
}
95108
}
96-
input.Seek(0, os.SEEK_SET)
97-
pbmax = lines
109+
input.Seek(0, io.SeekStart)
110+
pb.Finish()
98111
}
99112
}
100113

@@ -404,9 +417,10 @@ func main() {
404417
}
405418
}()
406419

420+
var pb *progressbar.ProgressBar
407421
if pbmax != 0 {
408422
pb = progressbar.NewOptions(pbmax,
409-
progressbar.OptionSetDescription("Progress"),
423+
progressbar.OptionSetDescription("Usernames nom'ed"),
410424
progressbar.OptionShowIts(),
411425
)
412426
}

0 commit comments

Comments
 (0)