Skip to content

Commit

Permalink
update v2
Browse files Browse the repository at this point in the history
  • Loading branch information
twiny committed Dec 10, 2021
1 parent 9e89968 commit f3fa550
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 216 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Iss Meftah
Copyright (c) 2021 - twiny

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
78 changes: 12 additions & 66 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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).

Expand Down
Loading

0 comments on commit f3fa550

Please sign in to comment.