Skip to content

Commit b57173b

Browse files
committed
Empty a record check when fetch dnslist
1 parent f596d59 commit b57173b

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

challenge/challenge.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ package challenge
22

33
import (
44
"crypto/tls"
5-
_ "net"
65
"net/http"
76
"fmt"
8-
_ "time"
97
"sync"
108
)
119
var mu sync.Mutex

fetch/fetch.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
package fetch
22

3-
import(
4-
"github.com/gocolly/colly/v2"
5-
"log"
3+
import (
64
"fmt"
5+
"log"
76
"net"
87
"strings"
8+
9+
"github.com/gocolly/colly/v2"
910
)
1011

1112
type Fetch struct {
12-
Addr string
13-
Num int
14-
Con int
13+
Addr string
14+
Num int
15+
Con int
1516
DomainsFile string
1617
}
1718

1819
type Record struct {
19-
IP string
20+
IP string
2021
Domains []string
2122
}
2223

@@ -68,7 +69,7 @@ func getDNSList(url string) {
6869
// Skip PTR records
6970
if i == 0 {
7071
IP = e.Text
71-
} else if i == 2 {
72+
} else if i == 2 && !IsStrEmpty(e.Text) {
7273
domains = strings.Split(e.Text, ", ")
7374
domainList = append(domainList, domains...)
7475
}
@@ -86,5 +87,5 @@ func getDNSList(url string) {
8687
if err != nil {
8788
log.Fatal("Cannot get DNS list", err)
8889
}
89-
90-
}
90+
91+
}

fetch/manager.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package fetch
2-
import(
3-
"sni-fetch/challenge"
2+
3+
import (
44
"fmt"
5+
"sni-fetch/challenge"
56
"strings"
67
"sync"
78
)
89

910
var mu sync.Mutex
11+
1012
// The number of sni met the conditions
1113
var vaildSNIs []string
14+
1215
// The number of already checked sni
1316
var sniNum = 1
1417

@@ -18,14 +21,14 @@ func HandleRecords(rs []Record) {
1821
fetch.Con = len(domainList)
1922
}
2023
dIndex := 0
21-
for i:= 0; i < fetch.Con; i++ {
24+
for i := 0; i < fetch.Con; i++ {
2225
go processChallenge(domainList[dIndex], ch)
2326
dIndex++
2427
}
2528

2629
for {
2730
// When a check task finished
28-
<- ch
31+
<-ch
2932
// All the SNI checks finished
3033
if sniNum == len(domainList) {
3134
break
@@ -47,7 +50,7 @@ func HandleRecords(rs []Record) {
4750
}
4851

4952
func processChallenge(domain string, ch chan struct{}) {
50-
if(challenge.Check(domain, &sniNum)) {
53+
if challenge.Check(domain, &sniNum) {
5154
vaildSNIs = append(vaildSNIs, domain)
5255
}
5356
mu.Lock()
@@ -58,4 +61,4 @@ func processChallenge(domain string, ch chan struct{}) {
5861

5962
func output() {
6063
fmt.Printf("\n\033[32m[Finished] Found %v SNIs available: \n %v\033[0m", len(vaildSNIs), strings.Join(vaildSNIs, "\n"))
61-
}
64+
}

fetch/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package fetch
2+
3+
import (
4+
"strings"
5+
)
6+
7+
func IsStrEmpty(s string) bool {
8+
trimmed := strings.TrimSpace(s)
9+
return len(trimmed) == 0
10+
}

0 commit comments

Comments
 (0)