]> Sergey Matveev's repositories - meta4ra.git/commitdiff
meta4ra-url-sort -6 v1.1.0
authorSergey Matveev <stargrave@stargrave.org>
Tue, 17 Feb 2026 12:22:22 +0000 (15:22 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 17 Feb 2026 12:22:34 +0000 (15:22 +0300)
cmd/sort.go
internal/common.go

index b36f2ba88437f5e312a3a98722cfc4963bd4cd44..9a522eeb1d2d1637cc250faaa5bb7a1f8c31b18f 100644 (file)
@@ -21,6 +21,8 @@ import (
        "fmt"
        "log"
        "math/rand/v2"
+       "net"
+       "net/url"
        "os"
        "sort"
        "strings"
@@ -70,6 +72,7 @@ func (by ByCC) Swap(i, j int) {
 }
 
 func runURLSort() {
+       ipv6 := flag.Bool("6", false, "Only IPv6-capable hostnames")
        flag.Usage = func() {
                fmt.Fprintf(flag.CommandLine.Output(),
                        "Usage: %s [options] [cc ...] <urls.txt\n", os.Args[0])
@@ -138,6 +141,16 @@ then Europe, then North America, then location-less, randomise remaining:
                if u.Priority == 999999 {
                        u.Priority = 0
                }
+               if *ipv6 {
+                       parsed, err := url.Parse(u.URL)
+                       if err != nil {
+                               continue
+                       }
+                       _, err = net.ResolveIPAddr("ip6", parsed.Hostname())
+                       if err != nil {
+                               continue
+                       }
+               }
                fmt.Println(u)
        }
 }
index 1c19d5046eb2ff355ca94a0a81adce172e7e96e7..85a7116968890a289eb996b8ba6cccd9d1017c2c 100644 (file)
@@ -21,7 +21,7 @@ import (
 )
 
 const (
-       Generator       = "meta4ra/1.0.0"
+       Generator       = "meta4ra/1.1.0"
        SigMediaTypePGP = "application/pgp-signature"
        SigMediaTypeSSH = "application/ssh-signature"
        BufLen          = 1 << 20