File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1
1
package dnslookup
2
2
3
3
import (
4
+ "math/rand"
4
5
"net"
5
6
"strings"
6
7
7
8
"github.com/sunggun-yu/dnsq/internal/models"
8
9
)
9
10
11
+ // randomHostname generates a random hostname
12
+ func randomHostname () string {
13
+ const charset = "abcdefghijklmnopqrstuvwxyz0123456789"
14
+ length := 8
15
+ // TODO: need to check length of hostname and see if it is over 255 long including the subdomain
16
+ b := make ([]byte , length )
17
+ for i := range b {
18
+ b [i ] = charset [rand .Intn (len (charset ))]
19
+ }
20
+ return string (b )
21
+ }
22
+
10
23
// GetDNSRecords returns DNS records for a given hostname
11
24
func GetDNSRecords (hostname string ) []models.DNSRecord {
12
25
var records []models.DNSRecord
13
26
currentHost := hostname
27
+ isWildcard := false
28
+
29
+ if strings .HasPrefix (hostname , "*." ) {
30
+ randomSubdomain := randomHostname ()
31
+ currentHost = randomSubdomain + hostname [1 :]
32
+ isWildcard = true
33
+ }
14
34
15
35
// CNAME lookup
16
36
cname , err := net .LookupCNAME (currentHost )
@@ -24,6 +44,12 @@ func GetDNSRecords(hostname string) []models.DNSRecord {
24
44
25
45
// A and AAAA lookup
26
46
ips , err := net .LookupIP (currentHost )
47
+
48
+ // if it is a wildcard, set the original hostname to the records
49
+ if isWildcard {
50
+ currentHost = hostname
51
+ }
52
+
27
53
if err == nil {
28
54
for _ , ip := range ips {
29
55
if ipv4 := ip .To4 (); ipv4 != nil {
You can’t perform that action at this time.
0 commit comments