-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1.81 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"os"
"regexp"
"golang.org/x/net/idna"
)
var usage = `
██████╗ ██╗ ██╗███╗ ██╗██╗ ██╗ ██████╗ ██████╗ ██████╗ ███████╗██████╗
██╔══██╗██║ ██║████╗ ██║╚██╗ ██╔╝██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗
██████╔╝██║ ██║██╔██╗ ██║ ╚████╔╝ ██║ ██║ ██║██║ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║╚██╗██║ ╚██╔╝ ██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝██║ ╚████║ ██║ ╚██████╗╚██████╔╝██████╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝
Converts punycode to unicode and vice-versa.
Usage:
punycoder <domain>
`
func main() {
if len(os.Args) != 2 {
fmt.Println(usage)
os.Exit(1)
}
domain := os.Args[1]
var re = regexp.MustCompile(`^xn--`)
switch {
case domain == "-h", domain == "--help":
fmt.Println(usage)
case re.Match([]byte(domain)):
//punycode was provided, convert to Unicode
unidomain, _ := idna.ToUnicode(domain)
fmt.Printf("%s\n", unidomain)
default:
//convert to ASCII punycode
asciidomain, _ := idna.ToASCII(domain)
fmt.Printf("%s\n", asciidomain)
}
}