-
Notifications
You must be signed in to change notification settings - Fork 20
/
whois.go
170 lines (143 loc) · 3.79 KB
/
whois.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package ripego
import (
"errors"
"github.com/sebastianbroekhoven/go-get-ianawhois"
)
var getNic = make(map[string]Whois)
const (
afrinic_whois_server = "whois.afrinic.net"
apnic_whois_server = "whois.apnic.net"
arin_whois_server = "whois.arin.net"
lacnic_whois_server = "whois.lacnic.net"
ripe_whois_server = "whois.ripe.net"
)
func init() {
getNic["afrinic"] = afrinic{}
getNic["apnic"] = apnic{}
getNic["arin"] = arin{}
getNic["lacnic"] = lacnic{}
getNic["ripe"] = ripe{}
}
// IpLookup function for lagacy, not breaking stuff
func IpLookup(ipaddr string) (w WhoisInfo, err error) {
if !isValidIp(ipaddr) {
return w, errors.New("Invalid IPv4 address: " + ipaddr)
}
w, err = getNicProvider(ipaddr).Check(ipaddr)
return w, err
}
// IPLookup function that returns IP information at provider and returns information.
func IPLookup(ipaddr string) (w WhoisInfo, err error) {
if !isValidIp(ipaddr) {
return w, errors.New("Invalid IPv4 address: " + ipaddr)
}
w, err = getNicProvider(ipaddr).Check(ipaddr)
return w, err
}
// IPv4Lookup function that returns IP information at provider and returns information.
func IPv4Lookup(ipaddr string) (w WhoisInfo, err error) {
if !isValidIp(ipaddr) {
return w, errors.New("Invalid IPv4 address: " + ipaddr)
}
resp, err := whois.Query(ipaddr)
if err != nil {
return w, errors.New("Query failed for: " + ipaddr)
}
server, org := whois.Server(resp)
if org == "afrinic" {
w, err = AfrinicCheck(ipaddr)
} else if org == "apnic" {
w, err = ApnicCheck(ipaddr)
} else if org == "arin" {
w, err = ArinCheck(ipaddr)
} else if org == "lacnic" {
w, err = LacnicCheck(ipaddr)
} else {
w, err = RipeCheck(ipaddr)
}
println(server)
// w, err = getNicProvider(ipaddr).Check(ipaddr)
return w, err
}
// IPv6Lookup function that returns IP information at provider and returns information.
func IPv6Lookup(ipaddr string) (w WhoisInfo, err error) {
if !isValidIPv6(ipaddr) {
return w, errors.New("Invalid IPv6 address: " + ipaddr)
}
resp, err := whois.Query(ipaddr)
if err != nil {
return w, errors.New("Query failed for: " + ipaddr)
}
server, org := whois.Server(resp)
if org == "afrinic" {
w, err = AfrinicCheck(ipaddr)
} else if org == "apnic" {
w, err = ApnicCheck6(ipaddr)
} else if org == "arin" {
w, err = ArinCheck(ipaddr)
} else if org == "lacnic" {
w, err = LacnicCheck(ipaddr)
} else {
w, err = RipeCheck6(ipaddr)
}
println(server)
// w, err = getNicProvider(ipaddr).Check(ipaddr)
return w, err
}
// GetNicProvider function that search for the right provider for the lookup.
func getNicProvider(ipaddr string) Whois {
var d = getNic["ripe"]
for w := range getNic {
if getNic[w].hasIP(ipaddr) {
d = getNic[w]
break
}
}
return d
}
// Whois intercate containing the resulting infomration.
type Whois interface {
Check(search string) (WhoisInfo, error)
hasIP(ipaddr string) bool
}
// WhoisInfo struct with information on IP address range.
type WhoisInfo struct {
Inetnum string
Netname string
Descr string
Country string
Organization string
AdminC string
TechC string
MntLower string
Status string
MntBy string
Created string
LastModified string
Source string
MntRoutes string
Person WhoisPerson
Route WhoisRoute
}
// WhoisPerson struct for Person information from provider.
type WhoisPerson struct {
Name string
Address string
Phone string
AbuseMailbox string
NicHdl string
MntBy string
Created string
LastModified string
Source string
}
// WhoisRoute struct for Route and Network information from provider.
type WhoisRoute struct {
Route string
Descr string
Origin string
MntBy string
Created string
LastModified string
Source string
}