update util.go

This commit is contained in:
xvzc 2022-01-07 22:44:03 +09:00
parent 6b630e9ad6
commit 2fd2503dd5
2 changed files with 67 additions and 61 deletions

26
util/doh.go Normal file
View File

@ -0,0 +1,26 @@
package util
import (
"log"
"github.com/babolivier/go-doh-client"
)
func DnsLookupOverHttps(dns string, domain string) (string, error) {
// Perform a A lookup on example.com
resolver := doh.Resolver{
Host: dns, // Change this with your favourite DoH-compliant resolver.
Class: doh.IN,
}
Debug(domain)
a, _, err := resolver.LookupA(domain)
if err != nil {
log.Println("Error looking up dns. ", err)
return "", err
}
ip := a[0].IP4
return ip, nil
}

View File

@ -4,83 +4,63 @@ import (
"log" "log"
"strings" "strings"
"github.com/babolivier/go-doh-client"
"github.com/xvzc/SpoofDPI/config" "github.com/xvzc/SpoofDPI/config"
) )
func ExtractDomain(message *[]byte) (string) { func ExtractDomain(message *[]byte) string {
i := 0 i := 0
for ; i < len(*message); i++ { for ; i < len(*message); i++ {
if (*message)[i] == '\n' { if (*message)[i] == '\n' {
i++ i++
break; break
} }
} }
for ; i < len(*message); i++ { for ; i < len(*message); i++ {
if (*message)[i] == ' ' { if (*message)[i] == ' ' {
i++ i++
break; break
} }
} }
j := i j := i
for ; j < len(*message); j++ { for ; j < len(*message); j++ {
if (*message)[j] == '\n' { if (*message)[j] == '\n' {
break; break
} }
} }
domain := strings.Split(string((*message)[i:j]), ":")[0] domain := strings.Split(string((*message)[i:j]), ":")[0]
return strings.TrimSpace(domain) return strings.TrimSpace(domain)
} }
func DnsLookupOverHttps(dns string, domain string)(string, error) { func ExtractMethod(message *[]byte) string {
// Perform a A lookup on example.com i := 0
resolver := doh.Resolver{ for ; i < len(*message); i++ {
Host: dns, // Change this with your favourite DoH-compliant resolver. if (*message)[i] == ' ' {
Class: doh.IN, break
} }
}
Debug(domain) method := strings.TrimSpace(string((*message)[:i]))
a, _, err := resolver.LookupA(domain) Debug(method)
if err != nil {
log.Println("Error looking up dns. ", err)
return "", err
}
ip := a[0].IP4 return strings.ToUpper(method)
return ip, nil
}
func ExtractMethod(message *[]byte) (string) {
i := 0
for ; i < len(*message); i++ {
if (*message)[i] == ' ' {
break;
}
}
method := strings.TrimSpace(string((*message)[:i]))
Debug(method)
return strings.ToUpper(method)
} }
func Debug(v ...interface{}) { func Debug(v ...interface{}) {
if config.GetConfig().Debug == false { if config.GetConfig().Debug == false {
return return
} }
log.Println(v...) log.Println(v...)
} }
func BytesToChunks(buf []byte) ([][]byte) { func BytesToChunks(buf []byte) [][]byte {
if len(buf) < 1 { if len(buf) < 1 {
return [][]byte{buf} return [][]byte{buf}
} }
return [][]byte{buf[:1], buf[1:]} return [][]byte{buf[:1], buf[1:]}
} }