-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
199 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,25 +2,17 @@ | |
|
||
a simple Go WHOIS Client API. | ||
|
||
## How it works | ||
- split domain name and finds corresponded WHOIS DB server from `db.yaml`. | ||
- dial a connection to the WHOIS server. | ||
- save the response. | ||
|
||
`whois.NewClient` function takes a `Dailer` argument. | ||
## API | ||
```go | ||
// Dialer | ||
type Dialer interface { | ||
DialContext(ctx context.Context, network, address string) (net.Conn, error) | ||
} | ||
Lookup(ctx context.Context, domain, server string) (string, error) | ||
WHOISHost(domain string) (string, error) | ||
TLDs() []string | ||
``` | ||
using a `nil` arg to `whois.NewClient` will create a client using local connect. | ||
|
||
## Install | ||
`go get github.com/twiny/whois` | ||
|
||
## Example | ||
- using local connection | ||
|
||
```go | ||
package main | ||
|
@@ -34,7 +26,11 @@ import ( | |
) | ||
|
||
func main() { | ||
client, err := whois.NewClient(nil) | ||
domain := "google.com" | ||
|
||
// to use Socks5 - this format 'socks5://username:[email protected]:1023' | ||
// otherwise use 'whois.Localhost' to use local connection | ||
client, err := whois.NewClient(whois.Localhost) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
|
@@ -43,72 +39,22 @@ func main() { | |
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
text, err := client.Lookup(ctx, "google.com") | ||
host, err := client.WHOISHost(domain) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
fmt.Println(text) | ||
fmt.Println("done.") | ||
} | ||
``` | ||
|
||
- using SOCKS5 connection | ||
```go | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/twiny/whois" | ||
"golang.org/x/net/proxy" | ||
) | ||
|
||
func main() { | ||
// create default client | ||
client, err := whois.NewClient(nil) | ||
resp, err := client.Lookup(ctx, "google.com", host) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
// using SOCKS5 | ||
// auth if required | ||
auth := &proxy.Auth{ | ||
User: "username", | ||
Password: "password", | ||
} | ||
dialer, err := proxy.SOCKS5("tcp", "hostname:port", auth, proxy.Direct) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
// clone default client | ||
proxyClient, err := client.Clone(dialer) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
// ctx | ||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) | ||
defer cancel() | ||
|
||
text, err := proxyClient.Lookup(ctx, "google.com") | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
fmt.Println(text) | ||
fmt.Println(resp) | ||
fmt.Println("done.") | ||
} | ||
``` | ||
|
||
## Tracking | ||
- If you wish to add more WHOIS Server please [create a PR](https://github.com/twiny/whois/pulls). | ||
|
||
|
Oops, something went wrong.