commit 4e1a541816bd3e9a4989de390ea0a85555778a8c Author: Kar@k5 Date: Tue Mar 10 20:18:25 2026 +0530 init diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a2e6923 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..b7d5900 --- /dev/null +++ b/README.md @@ -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 +``` + +## 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. diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4dca7ac --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module is-valid-domain + +go 1.25.5 + +require golang.org/x/net v0.51.0 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..a9d0e99 --- /dev/null +++ b/go.sum @@ -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= diff --git a/is-valid-domain b/is-valid-domain new file mode 100755 index 0000000..f2e5401 Binary files /dev/null and b/is-valid-domain differ diff --git a/main.go b/main.go new file mode 100644 index 0000000..82fed29 --- /dev/null +++ b/main.go @@ -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 \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") + } +}