-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from projectdiscovery/feature-adding-resolver-file
Adding resolver file support
- Loading branch information
Showing
8 changed files
with
97 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package fastdialer | ||
|
||
import ( | ||
"bufio" | ||
"net" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/dimchansky/utfbom" | ||
) | ||
|
||
func loadResolverFile() ([]string, error) { | ||
osResolversFilePath := os.ExpandEnv(filepath.FromSlash(ResolverFilePath)) | ||
|
||
if env, isset := os.LookupEnv("RESOLVERS_PATH"); isset && len(env) > 0 { | ||
osResolversFilePath = os.ExpandEnv(filepath.FromSlash(env)) | ||
} | ||
|
||
file, err := os.Open(osResolversFilePath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
|
||
var systemResolvers []string | ||
|
||
scanner := bufio.NewScanner(utfbom.SkipOnly(file)) | ||
for scanner.Scan() { | ||
resolverIP := HandleResolverLine(scanner.Text()) | ||
if resolverIP == "" { | ||
continue | ||
} | ||
systemResolvers = append(systemResolvers, net.JoinHostPort(resolverIP, "53")) | ||
} | ||
return systemResolvers, nil | ||
} | ||
|
||
// HandleLine a resolver file line | ||
func HandleResolverLine(raw string) (ip string) { | ||
// ignore comment | ||
if IsComment(raw) { | ||
return | ||
} | ||
|
||
// trim comment | ||
if HasComment(raw) { | ||
commentSplit := strings.Split(raw, commentChar) | ||
raw = commentSplit[0] | ||
} | ||
|
||
fields := strings.Fields(raw) | ||
if len(fields) == 0 { | ||
return | ||
} | ||
|
||
nameserverPrefix := fields[0] | ||
if nameserverPrefix != "nameserver" { | ||
return | ||
} | ||
|
||
ip = fields[1] | ||
if net.ParseIP(ip) == nil { | ||
return | ||
} | ||
|
||
return ip | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// +build !windows | ||
|
||
package fastdialer | ||
|
||
// ResolverFilePath in unix file os | ||
const ResolverFilePath = "/etc/resolv.conf" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// +build windows | ||
package fastdialer | ||
|
||
// To be implemented | ||
const ResolverFilePath = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters