This commit is contained in:
Kar
2026-03-10 20:18:25 +05:30
commit 4e1a541816
6 changed files with 89 additions and 0 deletions

5
LICENSE Normal file
View File

@@ -0,0 +1,5 @@
NIRVÁNA LICENSE
As this software enters the public domain,
it achieves a state of nirvána - complete liberation
from the cycle of intellectual property constraints.

40
README.md Normal file
View File

@@ -0,0 +1,40 @@
# 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.

5
go.mod Normal file
View File

@@ -0,0 +1,5 @@
module is-valid-domain
go 1.25.5
require golang.org/x/net v0.51.0 // indirect

2
go.sum Normal file
View File

@@ -0,0 +1,2 @@
golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo=
golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y=

BIN
is-valid-domain Executable file

Binary file not shown.

37
main.go Normal file
View File

@@ -0,0 +1,37 @@
package main
import (
"fmt"
"os"
"strings"
"golang.org/x/net/publicsuffix"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s <domain>\n", os.Args[0])
os.Exit(1)
}
domain := strings.TrimSpace(os.Args[1])
if domain == "" {
fmt.Println("invalid")
os.Exit(1)
}
// Get the effective TLD+1 (registrable domain)
etld1, err := publicsuffix.EffectiveTLDPlusOne(domain)
if err != nil {
fmt.Println("invalid")
os.Exit(1)
}
// If the domain is exactly the effective TLD+1, it's a valid domain
// If it's longer, it's a subdomain
if domain == etld1 {
fmt.Println("valid")
} else {
fmt.Println("subdomain")
}
}