-
Notifications
You must be signed in to change notification settings - Fork 2
/
client.go
61 lines (48 loc) · 1.15 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package greynoise
import (
"fmt"
"net"
"net/http"
"net/url"
)
type Client struct {
Key string
*http.Client
baseURL *url.URL
}
// Context will return more information about a given IP address. Returns time ranges, IP metadata (network owner,
// ASN,reverse DNS pointer, country), associated actors, activity tags, and raw port scan and web
// request information.
func (c *Client) Context(ip net.IP) (*ContextResult, error) {
request, err := c.NewRequest("GET", fmt.Sprintf("/v2/noise/context/%s", ip.String()), nil)
if err != nil {
return nil, err
}
output := ContextResult{}
if err := c.Do(request, &output); err != nil {
return nil, err
}
return &output, nil
}
type optionFn func(*Client)
// WithKey contains the Greynoise API key
func WithKey(key string) optionFn {
return func(c *Client) {
c.Key = key
}
}
// New returns a Greynoise API client
func New(options ...optionFn) (*Client, error) {
baseURL, err := url.Parse("https://enterprise.api.greynoise.io/v2/noise/")
if err != nil {
panic(err)
}
c := &Client{
baseURL: baseURL,
Client: http.DefaultClient,
}
for _, optionFn := range options {
optionFn(c)
}
return c, nil
}