41 lines
1.1 KiB
Markdown
41 lines
1.1 KiB
Markdown
# is-valid-domain
|
|
|
|
A CLI tool to validate domain names using the public suffix list from `golang.org/x/net/publicsuffix`.
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
./is-valid-domain <domain>
|
|
```
|
|
|
|
## Examples
|
|
|
|
```bash
|
|
./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
|
|
|
|
```bash
|
|
go build -o is-valid-domain main.go
|
|
```
|
|
|
|
## How it Works
|
|
|
|
The tool uses `publicsuffix.EffectiveTLDPlusOne()` to determine the registrable domain:
|
|
|
|
1. If the input domain exactly matches the effective TLD+1 → **valid**
|
|
2. If the input domain is longer than the effective TLD+1 → **subdomain**
|
|
3. 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.
|