Skip to content

Commit

Permalink
tld whois query support
Browse files Browse the repository at this point in the history
  • Loading branch information
likexian committed Nov 19, 2019
1 parent bad8d75 commit 4056640
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 24 deletions.
8 changes: 4 additions & 4 deletions cmd/whois/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Binary distributions available for Linux x86 and x86_64.

### linux x86_64

wget https://github.com/likexian/whois-go/releases/download/v1.2.0/whois.linux-amd64.tar.gz
wget https://github.com/likexian/whois-go/releases/download/v1.3.0/whois.linux-amd64.tar.gz

OR

curl https://github.com/likexian/whois-go/releases/download/v1.2.0/whois.linux-amd64.tar.gz -OL
curl https://github.com/likexian/whois-go/releases/download/v1.3.0/whois.linux-amd64.tar.gz -OL

### linux x86

wget https://github.com/likexian/whois-go/releases/download/v1.2.0/whois.linux-386.tar.gz
wget https://github.com/likexian/whois-go/releases/download/v1.3.0/whois.linux-386.tar.gz

OR

curl https://github.com/likexian/whois-go/releases/download/v1.2.0/whois.linux-386.tar.gz -OL
curl https://github.com/likexian/whois-go/releases/download/v1.3.0/whois.linux-386.tar.gz -OL

## install whois

Expand Down
35 changes: 16 additions & 19 deletions whois.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,18 @@ import (
"time"
)

// Query server const
const (
IP_WHOIS_SERVER = "whois.iana.org"
// IANA_WHOIS_SERVER is iana whois server
IANA_WHOIS_SERVER = "whois.iana.org"
// DOMAIN_WHOIS_SERVER is tld whois server
DOMAIN_WHOIS_SERVER = "whois-servers.net"
WHOIS_PORT = "43"
// WHOIS_PORT is default whois port
WHOIS_PORT = "43"
)

// Version returns package version
func Version() string {
return "1.2.0"
return "1.3.0"
}

// Author returns package author
Expand Down Expand Up @@ -91,21 +93,17 @@ func Whois(domain string, servers ...string) (result string, err error) {

// query do the query
func query(domain string, servers ...string) (result string, err error) {
var server string
server := IANA_WHOIS_SERVER
if len(servers) == 0 || servers[0] == "" {
if IsIpv4(domain) {
server = IP_WHOIS_SERVER
} else {
if !IsIpv4(domain) {
domains := strings.Split(domain, ".")
if len(domains) < 2 {
err = fmt.Errorf("Domain %s is invalid", domain)
return
if len(domains) > 1 {
ext := domains[len(domains)-1]
if strings.Contains(ext, "/") {
ext = strings.Split(ext, "/")[0]
}
server = ext + "." + DOMAIN_WHOIS_SERVER
}
ext := domains[len(domains)-1]
if strings.Contains(ext, "/") {
ext = strings.Split(ext, "/")[0]
}
server = ext + "." + DOMAIN_WHOIS_SERVER
}
} else {
server = strings.ToLower(servers[0])
Expand All @@ -127,9 +125,8 @@ func query(domain string, servers ...string) (result string, err error) {
return
}

buffer, e := ioutil.ReadAll(conn)
if e != nil {
err = e
buffer, err := ioutil.ReadAll(conn)
if err != nil {
return
}

Expand Down
2 changes: 1 addition & 1 deletion whois_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func TestVersion(t *testing.T) {
func TestWhoisFail(t *testing.T) {
tests := []string{
"",
"likexian",
"likexian.jp?e",
"8.8.8.888",
}
Expand All @@ -50,6 +49,7 @@ func TestWhoisFail(t *testing.T) {

func TestWhois(t *testing.T) {
tests := []string{
"com",
"likexian.com",
"google.net",
"google.org",
Expand Down

0 comments on commit 4056640

Please sign in to comment.