feat: Add [DOMAIN_EXPIRATION] placeholder for monitoring domain expiration using WHOIS (#325)
* feat: Add [DOMAIN_EXPIRATION] placeholder for monitoring domain expiration using WHOIS * test: Fix issue caused by possibility of millisecond elapsed during previous tests * test: Fix test with different behavior based on architecture * docs: Revert accidental change to starttls example * docs: Fix mistake in comment for Condition.hasIPPlaceholder()
This commit is contained in:
2
vendor/github.com/TwiN/whois/.gitignore
generated
vendored
Normal file
2
vendor/github.com/TwiN/whois/.gitignore
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
.idea
|
||||
bin
|
21
vendor/github.com/TwiN/whois/LICENSE
generated
vendored
Normal file
21
vendor/github.com/TwiN/whois/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 TwiN
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
4
vendor/github.com/TwiN/whois/Makefile
generated
vendored
Normal file
4
vendor/github.com/TwiN/whois/Makefile
generated
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
.PHONY: build-binaries
|
||||
|
||||
build-binaries:
|
||||
./scripts/build.sh
|
65
vendor/github.com/TwiN/whois/README.md
generated
vendored
Normal file
65
vendor/github.com/TwiN/whois/README.md
generated
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
# whois
|
||||

|
||||
|
||||
Lightweight library for retrieving WHOIS information on a domain.
|
||||
|
||||
It automatically retrieves the appropriate WHOIS server based on the domain's TLD by first querying IANA.
|
||||
|
||||
|
||||
## Usage
|
||||
### As an executable
|
||||
To install it:
|
||||
```console
|
||||
go install github.com/TwiN/whois/cmd/whois@latest
|
||||
```
|
||||
To run it:
|
||||
```console
|
||||
whois example.com
|
||||
```
|
||||
|
||||
### As a library
|
||||
```console
|
||||
go get github.com/TwiN/whois
|
||||
```
|
||||
|
||||
#### Query
|
||||
If all you want is the text a WHOIS server would return you, you can use the `Query` method of the `whois.Client` type:
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/TwiN/whois"
|
||||
|
||||
func main() {
|
||||
client := whois.NewClient()
|
||||
output, err := client.Query("example.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println(output)
|
||||
}
|
||||
```
|
||||
|
||||
#### QueryAndParse
|
||||
If you want specific pieces of information, you can use the `QueryAndParse` method of the `whois.Client` type:
|
||||
```go
|
||||
package main
|
||||
|
||||
import "github.com/TwiN/whois"
|
||||
|
||||
func main() {
|
||||
client := whois.NewClient()
|
||||
response, err := client.QueryAndParse("example.com")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
println(response.ExpirationDate.String())
|
||||
}
|
||||
```
|
||||
Note that because there is no standardized format for WHOIS responses, this parsing may not be successful for every single TLD.
|
||||
|
||||
Currently, the only fields parsed are:
|
||||
- `ExpirationDate`: The time.Time at which the domain will expire
|
||||
- `DomainStatuses`: The statuses that the domain currently has (e.g. `clientTransferProhibited`)
|
||||
- `NameServers`: The nameservers currently tied to the domain
|
||||
|
||||
If you'd like one or more other fields to be parsed, please don't be shy and create an issue or a pull request.
|
94
vendor/github.com/TwiN/whois/whois.go
generated
vendored
Normal file
94
vendor/github.com/TwiN/whois/whois.go
generated
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
package whois
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
ianaWHOISServerAddress = "whois.iana.org:43"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
whoisServerAddress string
|
||||
}
|
||||
|
||||
func NewClient() *Client {
|
||||
return &Client{
|
||||
whoisServerAddress: ianaWHOISServerAddress,
|
||||
}
|
||||
}
|
||||
|
||||
func (c Client) Query(domain string) (string, error) {
|
||||
parts := strings.Split(domain, ".")
|
||||
output, err := c.query(c.whoisServerAddress, parts[len(parts)-1])
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if strings.Contains(output, "whois:") {
|
||||
startIndex := strings.Index(output, "whois:") + 6
|
||||
endIndex := strings.Index(output[startIndex:], "\n") + startIndex
|
||||
whois := strings.TrimSpace(output[startIndex:endIndex])
|
||||
if referOutput, err := c.query(whois+":43", domain); err == nil {
|
||||
return referOutput, nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func (c Client) query(whoisServerAddress, domain string) (string, error) {
|
||||
connection, err := net.DialTimeout("tcp", whoisServerAddress, 10*time.Second)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer connection.Close()
|
||||
connection.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
_, err = connection.Write([]byte(domain + "\r\n"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
output, err := io.ReadAll(connection)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(output), nil
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
ExpirationDate time.Time
|
||||
DomainStatuses []string
|
||||
NameServers []string
|
||||
}
|
||||
|
||||
// QueryAndParse tries to parse the response from the WHOIS server
|
||||
// There is no standardized format for WHOIS responses, so this is an attempt at best.
|
||||
//
|
||||
// Being the selfish person that I am, I also only parse the fields that I need.
|
||||
// If you need more fields, please open an issue or pull request.
|
||||
func (c Client) QueryAndParse(domain string) (*Response, error) {
|
||||
text, err := c.Query(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
response := Response{}
|
||||
for _, line := range strings.Split(text, "\n") {
|
||||
line = strings.TrimSpace(line)
|
||||
valueStartIndex := strings.Index(line, ":")
|
||||
if valueStartIndex == -1 {
|
||||
continue
|
||||
}
|
||||
key := strings.ToLower(strings.TrimSpace(line[:valueStartIndex]))
|
||||
value := strings.TrimSpace(line[valueStartIndex+1:])
|
||||
if response.ExpirationDate.Unix() != 0 && strings.Contains(key, "expir") && strings.Contains(key, "date") {
|
||||
response.ExpirationDate, _ = time.Parse(time.RFC3339, strings.ToUpper(value))
|
||||
} else if strings.Contains(key, "domain status") {
|
||||
response.DomainStatuses = append(response.DomainStatuses, value)
|
||||
} else if strings.Contains(key, "name server") {
|
||||
response.NameServers = append(response.NameServers, value)
|
||||
}
|
||||
}
|
||||
return &response, nil
|
||||
}
|
Reference in New Issue
Block a user