-
Notifications
You must be signed in to change notification settings - Fork 2
/
local_core.go
70 lines (66 loc) · 1.64 KB
/
local_core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//go:build linux
package main
import (
"bufio"
"os"
"os/exec"
"regexp"
"runtime"
"strings"
"sync"
"github.com/sirupsen/logrus"
)
func RunLocalCore(domain, area string) (output []string) {
var outputLock sync.Mutex
var pool sync.WaitGroup
dnsFileName := "./dns.txt"
if _, err := os.Stat(dnsFileName); err != nil {
panic("Can't find dns.txt")
}
file, err := os.Open(dnsFileName)
if err != nil {
panic("Can't open dns.txt")
}
defer file.Close()
scanner := bufio.NewScanner(file)
logrus.Info("[+]Your system is ", runtime.GOOS)
for scanner.Scan() {
line := scanner.Text()
pool.Add(1)
go func(domain, line string) {
var cmd *exec.Cmd
var r *regexp.Regexp
switch runtime.GOOS {
case "windows":
// Address: 210.0.255.251
// Addresses: 210.0.255.251
cmd = exec.Command("nslookup.exe", domain, line)
r = regexp.MustCompile(`Addresse?s?:\s+(\d+\.\d+\.\d+\.\d+)`)
case "linux":
cmd = exec.Command("nslookup", domain, line)
r = regexp.MustCompile(`Address:\s+(\d+\.\d+\.\d+\.\d+)`)
default:
logrus.Error("[-]Unsupported system")
return
}
if ip, err := cmd.CombinedOutput(); err == nil {
// logrus.Debug(string(ip))
tmpOutput := r.FindAllStringSubmatch(string(ip), -1)
logrus.Debug(tmpOutput)
for _, tmpIP := range tmpOutput {
if tmpIP[1] == line || strings.Contains(tmpIP[1], "#") {
logrus.Debug("[-]ignore ", tmpIP[0], " -> ", tmpIP[1])
continue
}
logrus.Debug(tmpIP[0], " -> ", tmpIP[1])
outputLock.Lock()
output = append(output, tmpIP[1])
outputLock.Unlock()
}
}
pool.Done()
}(domain, line)
}
pool.Wait()
return output
}