mirror of
https://github.com/anotherhadi/iknowyou.git
synced 2026-04-11 16:37:25 +02:00
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package whois
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/anotherhadi/iknowyou/internal/tools"
|
|
)
|
|
|
|
const (
|
|
name = "whois"
|
|
description = "WHOIS lookup for domain registration and IP ownership information."
|
|
link = "https://en.wikipedia.org/wiki/WHOIS"
|
|
icon = ""
|
|
)
|
|
|
|
type Runner struct{}
|
|
|
|
func New() tools.ToolRunner { return &Runner{} }
|
|
|
|
func (r *Runner) Name() string { return name }
|
|
func (r *Runner) Description() string { return description }
|
|
func (r *Runner) Link() string { return link }
|
|
func (r *Runner) Icon() string { return icon }
|
|
|
|
func (r *Runner) InputTypes() []tools.InputType {
|
|
return []tools.InputType{tools.InputTypeDomain, tools.InputTypeIP}
|
|
}
|
|
|
|
func (r *Runner) Available() (bool, string) {
|
|
if _, err := exec.LookPath("whois"); err != nil {
|
|
return false, "whois binary not found in PATH"
|
|
}
|
|
return true, ""
|
|
}
|
|
|
|
func (r *Runner) Dependencies() []string { return []string{"whois"} }
|
|
|
|
func (r *Runner) Run(ctx context.Context, target string, _ tools.InputType, out chan<- tools.Event) error {
|
|
defer close(out)
|
|
|
|
cmd := exec.CommandContext(ctx, "whois", target)
|
|
output, err := cmd.Output()
|
|
|
|
if err != nil && ctx.Err() != nil {
|
|
out <- tools.Event{Tool: name, Type: tools.EventTypeError, Payload: "scan cancelled"}
|
|
out <- tools.Event{Tool: name, Type: tools.EventTypeCount, Payload: 0}
|
|
out <- tools.Event{Tool: name, Type: tools.EventTypeDone}
|
|
return nil
|
|
}
|
|
|
|
result := strings.TrimSpace(string(output))
|
|
count := 0
|
|
if result != "" {
|
|
out <- tools.Event{Tool: name, Type: tools.EventTypeOutput, Payload: result}
|
|
count = 1
|
|
}
|
|
out <- tools.Event{Tool: name, Type: tools.EventTypeCount, Payload: count}
|
|
out <- tools.Event{Tool: name, Type: tools.EventTypeDone}
|
|
return nil
|
|
}
|