Fix -x flag (#35)
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
d9a5e177aa
commit
3085c116d6
4 changed files with 32 additions and 5 deletions
|
@ -98,6 +98,15 @@ func TestQUIC(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func TestReverse(t *testing.T) {
|
||||
app := prepareCLI()
|
||||
args := os.Args[0:1]
|
||||
args = append(args, "-x")
|
||||
args = append(args, "8.8.8.8")
|
||||
err := app.Run(args)
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
func FuzzCli(f *testing.F) {
|
||||
testcases := []string{"git.froth.zone", "", "!12345", "google.com.edu.org.fr"}
|
||||
for _, tc := range testcases {
|
||||
|
|
11
query.go
11
query.go
|
@ -48,6 +48,17 @@ func doQuery(c *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
msg := new(dns.Msg)
|
||||
|
||||
if Options.Reverse {
|
||||
if dns.TypeToString[Options.Answers.Request] == "A" {
|
||||
Options.Answers.Request = dns.StringToType["PTR"]
|
||||
}
|
||||
Options.Answers.Name, err = util.ReverseDNS(Options.Answers.Name, Options.Answers.Request)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// if the domain is not canonical, make it canonical
|
||||
if !strings.HasSuffix(Options.Answers.Name, ".") {
|
||||
Options.Answers.Name = fmt.Sprintf("%s.", Options.Answers.Name)
|
||||
|
|
|
@ -11,7 +11,8 @@ import (
|
|||
)
|
||||
|
||||
// Given an IP or phone number, return a canonical string to be queried
|
||||
func ReverseDNS(address string, query string) (string, error) {
|
||||
func ReverseDNS(address string, querInt uint16) (string, error) {
|
||||
query := dns.TypeToString[querInt]
|
||||
if query == "PTR" {
|
||||
return dns.ReverseAddr(address)
|
||||
} else if query == "NAPTR" {
|
||||
|
|
|
@ -5,17 +5,23 @@ package util
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
var (
|
||||
PTR = dns.StringToType["PTR"]
|
||||
NAPTR = dns.StringToType["NAPTR"]
|
||||
)
|
||||
|
||||
func TestIPv4(t *testing.T) {
|
||||
act, err := ReverseDNS("8.8.4.4", "PTR")
|
||||
act, err := ReverseDNS("8.8.4.4", PTR)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, act, "4.4.8.8.in-addr.arpa.", "IPv4 reverse")
|
||||
}
|
||||
|
||||
func TestIPv6(t *testing.T) {
|
||||
act, err := ReverseDNS("2606:4700:4700::1111", "PTR")
|
||||
act, err := ReverseDNS("2606:4700:4700::1111", PTR)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, act, "1.1.1.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.7.4.0.0.7.4.6.0.6.2.ip6.arpa.", "IPv6 reverse")
|
||||
}
|
||||
|
@ -31,13 +37,13 @@ func TestNAPTR(t *testing.T) {
|
|||
{"17705551212", "2.1.2.1.5.5.5.0.7.7.1.e164.arpa."},
|
||||
}
|
||||
for _, test := range tests {
|
||||
act, err := ReverseDNS(test.in, "NAPTR")
|
||||
act, err := ReverseDNS(test.in, NAPTR)
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, test.want, act)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalid(t *testing.T) {
|
||||
_, err := ReverseDNS("AAAAA", "A")
|
||||
_, err := ReverseDNS("AAAAA", 1)
|
||||
assert.NotNil(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue