is-valid-domain
A CLI tool to validate domain names using the public suffix list from golang.org/x/net/publicsuffix.
Usage
./is-valid-domain <domain>
Examples
./is-valid-domain 029.cyou # Output: valid
./is-valid-domain siliconpin.co.in # Output: valid
./is-valid-domain co.siliconpin.in # Output: subdomain
./is-valid-domain invalid..domain # Output: invalid
Output Categories
- valid - The domain is a registrable domain (effective TLD+1)
- subdomain - The domain is a subdomain of a registrable domain
- invalid - The domain is malformed or not a valid domain name
Installation
go build -o is-valid-domain main.go
How it Works
The tool uses publicsuffix.EffectiveTLDPlusOne() to determine the registrable domain:
- If the input domain exactly matches the effective TLD+1 → valid
- If the input domain is longer than the effective TLD+1 → subdomain
- If there's an error parsing the domain → invalid
This leverages the official public suffix list to correctly handle complex TLD structures like .co.in, .co.uk, etc.
Description