whoisparser

package module
v1.25.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

WhoisParser

License GoDoc Go Report Card Build Status Code Cover

WhoisParser is a simple Go module for domain, IP, and AS whois information parsing.

Overview

This module parses the provided domain, IP, or AS whois information and returns a readable data struct.

Verified Extensions

It is supposed to be working with all domain extensions, but verified extensions must works, because I have checked them one by one manually.

If there is any problem, please feel free to open a new issue.

Binary distributions

For binary distributions of whois information query and parsing, please download whois release tool.

Installation

go get github.com/0xDezzy/whois-parser

Importing

import (
    "github.com/0xDezzy/whois-parser"
)

Documentation

Visit the docs on GoDoc

Examples

Domain WHOIS
package main

import (
    "fmt"
    "github.com/likexian/whois"
    "github.com/0xDezzy/whois-parser"
)

func main() {
    domain := "example.com"
    whoisRaw, err := whois.Whois(domain)
    if err != nil {
        fmt.Println(err)
        return
    }

    result, err := whoisparser.Parse(whoisRaw)
    if err == nil && result.Domain != nil {
        // Print the domain status
        fmt.Println("Domain Status:", result.Domain.Status)

        // Print the domain created date
        fmt.Println("Created Date:", result.Domain.CreatedDate)

        // Print the domain expiration date
        fmt.Println("Expiration Date:", result.Domain.ExpirationDate)

        // Print the registrar name
        if result.Registrar != nil {
            fmt.Println("Registrar Name:", result.Registrar.Name)
        }

        // Print the registrant name
        if result.Registrant != nil {
            fmt.Println("Registrant Name:", result.Registrant.Name)
        }

        // Print the registrant email address
        if result.Registrant != nil {
            fmt.Println("Registrant Email:", result.Registrant.Email)
        }
    } else {
        fmt.Println(err)
    }
}
IP WHOIS
package main

import (
    "fmt"
    "github.com/likexian/whois"
    "github.com/0xDezzy/whois-parser"
)

func main() {
    ip := "8.8.8.8"
    whoisRaw, err := whois.Whois(ip)
    if err != nil {
        fmt.Println(err)
        return
    }

    result, err := whoisparser.Parse(whoisRaw)
    if err == nil && result.IP != nil && len(result.IP.Networks) > 0 {
        network := result.IP.Networks[0]

        // Print the IP range
        fmt.Println("IP Range:", network.Range)

        // Print the CIDR blocks
        fmt.Println("CIDR Blocks:", network.CIDR)

        // Print the network name
        fmt.Println("Network Name:", network.Name)

        // Print the organization name
        if network.Organization != nil {
            fmt.Println("Organization:", network.Organization.Organization)
        }

        // Print the abuse contact email
        if result.IP.Abuse != nil {
            fmt.Println("Abuse Contact Email:", result.IP.Abuse.Email)
        }
    } else {
        fmt.Println(err)
    }
}
AS WHOIS
package main

import (
    "fmt"
    "github.com/likexian/whois"
    "github.com/0xDezzy/whois-parser"
)

func main() {
    asNumber := "AS15169" // Google's AS number
    whoisRaw, err := whois.Whois(asNumber)
    if err != nil {
        fmt.Println(err)
        return
    }

    result, err := whoisparser.Parse(whoisRaw)
    if err == nil && result.AS != nil {
        // Print the AS number
        fmt.Println("AS Number:", result.AS.Number)

        // Print the AS name
        fmt.Println("AS Name:", result.AS.Name)

        // Print the organization name
        if result.AS.Organization != nil {
            fmt.Println("Organization:", result.AS.Organization.Organization)
        }

        // Print the technical contact email
        if result.AS.Technical != nil {
            fmt.Println("Technical Contact Email:", result.AS.Technical.Email)
        }
    } else {
        fmt.Println(err)
    }
}

Whois information query

Please refer to whois

License

Copyright 2014-2024 Li Kexian

Licensed under the Apache License 2.0

Donation

If this project is helpful, please share it with friends.

If you want to thank me, you can give me a cup of coffee.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFoundDomain domain is not found
	ErrNotFoundDomain = errors.New("whoisparser: domain is not found")
	// ErrReservedDomain domain is reserved
	ErrReservedDomain = errors.New("whoisparser: domain is reserved to register")
	// ErrPremiumDomain domain is available to register at premium price
	ErrPremiumDomain = errors.New("whoisparser: domain is available at premium price")
	// ErrBlockedDomain domain is blocked due to brand protection
	ErrBlockedDomain = errors.New("whoisparser: domain is blocked due to brand protection")
	// ErrDomainDataInvalid domain whois data is invalid
	ErrDomainDataInvalid = errors.New("whoisparser: domain whois data is invalid")
	// ErrDomainLimitExceed domain whois query is limited
	ErrDomainLimitExceed = errors.New("whoisparser: domain whois query limit exceeded")
	// ErrNotFoundIP IP address is not found
	ErrNotFoundIP = errors.New("whoisparser: IP address is not found")
	// ErrIPDataInvalid IP whois data is invalid
	ErrIPDataInvalid = errors.New("whoisparser: IP whois data is invalid")
	// ErrIPLimitExceed IP whois query is limited
	ErrIPLimitExceed = errors.New("whoisparser: IP whois query limit exceeded")
	// ErrNotFoundAS AS number is not found
	ErrNotFoundAS = errors.New("whoisparser: AS number is not found")
	// ErrASDataInvalid AS whois data is invalid
	ErrASDataInvalid = errors.New("whoisparser: AS whois data is invalid")
	// ErrASLimitExceed AS whois query is limited
	ErrASLimitExceed = errors.New("whoisparser: AS whois query limit exceeded")
)

Functions

func Author

func Author() string

Author returns package author

func License

func License() string

License returns package license

func Prepare

func Prepare(text, ext string) (string, bool)

Prepare do prepare the whois info for parsing

func Version

func Version() string

Version returns package version

Types

type ASInfo

type ASInfo struct {
	Number       string   `json:"number,omitempty"`
	Name         string   `json:"name,omitempty"`
	Handle       string   `json:"handle,omitempty"`
	RegDate      string   `json:"reg_date,omitempty"`
	Updated      string   `json:"updated,omitempty"`
	Ref          string   `json:"ref,omitempty"`
	Organization *Contact `json:"organization,omitempty"`
	Routing      *Contact `json:"routing,omitempty"`
	Technical    *Contact `json:"technical,omitempty"`
	Abuse        *Contact `json:"abuse,omitempty"`
}

ASInfo stores AS WHOIS information.

type Contact

type Contact struct {
	ID               string `json:"id,omitempty"`
	Name             string `json:"name,omitempty"`
	Organization     string `json:"organization,omitempty"`
	Street           string `json:"street,omitempty"`
	City             string `json:"city,omitempty"`
	Province         string `json:"province,omitempty"`
	PostalCode       string `json:"postal_code,omitempty"`
	Country          string `json:"country,omitempty"`
	Phone            string `json:"phone,omitempty"`
	PhoneExt         string `json:"phone_ext,omitempty"`
	Fax              string `json:"fax,omitempty"`
	FaxExt           string `json:"fax_ext,omitempty"`
	Email            string `json:"email,omitempty"`
	ReferralURL      string `json:"referral_url,omitempty"`
	RegistrationDate string `json:"registration_date,omitempty"`
	Updated          string `json:"updated,omitempty"`
	Comment          string `json:"comment,omitempty"`
}

Contact stores contact information.

type Domain

type Domain struct {
	ID                   string     `json:"id,omitempty"`
	Domain               string     `json:"domain,omitempty"`
	Punycode             string     `json:"punycode,omitempty"`
	Name                 string     `json:"name,omitempty"`
	Extension            string     `json:"extension,omitempty"`
	WhoisServer          string     `json:"whois_server,omitempty"`
	Status               []string   `json:"status,omitempty"`
	NameServers          []string   `json:"name_servers,omitempty"`
	DNSSec               bool       `json:"dnssec,omitempty"`
	CreatedDate          string     `json:"created_date,omitempty"`
	CreatedDateInTime    *time.Time `json:"created_date_in_time,omitempty"`
	UpdatedDate          string     `json:"updated_date,omitempty"`
	UpdatedDateInTime    *time.Time `json:"updated_date_in_time,omitempty"`
	ExpirationDate       string     `json:"expiration_date,omitempty"`
	ExpirationDateInTime *time.Time `json:"expiration_date_in_time,omitempty"`
}

Domain stores domain name information.

type IPInfo

type IPInfo struct {
	Networks  []*Network `json:"networks,omitempty"`
	Abuse     *Contact   `json:"abuse,omitempty"`
	Technical *Contact   `json:"technical,omitempty"`
	Routing   *Contact   `json:"routing,omitempty"`
}

IPInfo stores IP WHOIS information.

type Network

type Network struct {
	Range            string   `json:"range,omitempty"`
	CIDR             []string `json:"cidr,omitempty"`
	Name             string   `json:"name,omitempty"`
	Handle           string   `json:"handle,omitempty"`
	Parent           string   `json:"parent,omitempty"`
	Type             string   `json:"type,omitempty"`
	OriginAS         string   `json:"origin_as,omitempty"`
	OrganizationName string   `json:"organization_name,omitempty"` // Add this line
	Organization     *Contact `json:"organization,omitempty"`
	Customer         *Contact `json:"customer,omitempty"`
	RegDate          string   `json:"reg_date,omitempty"`
	Updated          string   `json:"updated,omitempty"`
	Comment          string   `json:"comment,omitempty"`
	Ref              string   `json:"ref,omitempty"`
}

Network stores IP network information.

type WhoisInfo

type WhoisInfo struct {
	Domain         *Domain  `json:"domain,omitempty"`
	Registrar      *Contact `json:"registrar,omitempty"`
	Registrant     *Contact `json:"registrant,omitempty"`
	Administrative *Contact `json:"administrative,omitempty"`
	Technical      *Contact `json:"technical,omitempty"`
	Billing        *Contact `json:"billing,omitempty"`
	IP             *IPInfo  `json:"ip,omitempty"`
	AS             *ASInfo  `json:"as,omitempty"`
}

WhoisInfo stores domain, IP, or AS WHOIS information.

func Parse

func Parse(text string) (whoisInfo WhoisInfo, err error)

Parse returns parsed whois info for domain, IP, or AS

func ParseASWhois

func ParseASWhois(text string) (whoisInfo WhoisInfo, err error)

parseASWhois parses AS WHOIS information.

func ParseDomainWhois

func ParseDomainWhois(text string) (whoisInfo WhoisInfo, err error)

parseDomainWhois parses domain whois information

func ParseIPWhois

func ParseIPWhois(text string) (whoisInfo WhoisInfo, err error)

ParseIPWhois parses IP WHOIS information.

Directories

Path Synopsis
examples
asn
ip

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL