Skip to content

Commit

Permalink
Empty a record check when fetch dnslist
Browse files Browse the repository at this point in the history
  • Loading branch information
HelloLingC committed Nov 14, 2023
1 parent f596d59 commit b57173b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
2 changes: 0 additions & 2 deletions challenge/challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package challenge

import (
"crypto/tls"
_ "net"
"net/http"
"fmt"
_ "time"
"sync"
)
var mu sync.Mutex
Expand Down
21 changes: 11 additions & 10 deletions fetch/fetch.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package fetch

import(
"github.com/gocolly/colly/v2"
"log"
import (
"fmt"
"log"
"net"
"strings"

"github.com/gocolly/colly/v2"
)

type Fetch struct {
Addr string
Num int
Con int
Addr string
Num int
Con int
DomainsFile string
}

type Record struct {
IP string
IP string
Domains []string
}

Expand Down Expand Up @@ -68,7 +69,7 @@ func getDNSList(url string) {
// Skip PTR records
if i == 0 {
IP = e.Text
} else if i == 2 {
} else if i == 2 && !IsStrEmpty(e.Text) {
domains = strings.Split(e.Text, ", ")
domainList = append(domainList, domains...)
}
Expand All @@ -86,5 +87,5 @@ func getDNSList(url string) {
if err != nil {
log.Fatal("Cannot get DNS list", err)
}
}

}
15 changes: 9 additions & 6 deletions fetch/manager.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package fetch
import(
"sni-fetch/challenge"

import (
"fmt"
"sni-fetch/challenge"
"strings"
"sync"
)

var mu sync.Mutex

// The number of sni met the conditions
var vaildSNIs []string

// The number of already checked sni
var sniNum = 1

Expand All @@ -18,14 +21,14 @@ func HandleRecords(rs []Record) {
fetch.Con = len(domainList)
}
dIndex := 0
for i:= 0; i < fetch.Con; i++ {
for i := 0; i < fetch.Con; i++ {
go processChallenge(domainList[dIndex], ch)
dIndex++
}

for {
// When a check task finished
<- ch
<-ch
// All the SNI checks finished
if sniNum == len(domainList) {
break
Expand All @@ -47,7 +50,7 @@ func HandleRecords(rs []Record) {
}

func processChallenge(domain string, ch chan struct{}) {
if(challenge.Check(domain, &sniNum)) {
if challenge.Check(domain, &sniNum) {
vaildSNIs = append(vaildSNIs, domain)
}
mu.Lock()
Expand All @@ -58,4 +61,4 @@ func processChallenge(domain string, ch chan struct{}) {

func output() {
fmt.Printf("\n\033[32m[Finished] Found %v SNIs available: \n %v\033[0m", len(vaildSNIs), strings.Join(vaildSNIs, "\n"))
}
}
10 changes: 10 additions & 0 deletions fetch/util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package fetch

import (
"strings"
)

func IsStrEmpty(s string) bool {
trimmed := strings.TrimSpace(s)
return len(trimmed) == 0
}

0 comments on commit b57173b

Please sign in to comment.