master
兔子 10 months ago
parent 4074adfcd9
commit e5db22aa52

@ -1,6 +1,7 @@
mkdir bin mkdir bin
set GOOS=windows set GOOS=windows
set GOARCH=amd64 set GOARCH=amd64
set CGO_ENABLED=0
go build -o .\bin\b612_x86_64.exe -ldflags "-w -s" . go build -o .\bin\b612_x86_64.exe -ldflags "-w -s" .
upx -9 .\bin\b612_x86_64.exe upx -9 .\bin\b612_x86_64.exe
set GOARCH=386 set GOARCH=386

@ -19,6 +19,10 @@ var Cmd = &cobra.Command{
Short: "分析nfts磁盘文件占用", Short: "分析nfts磁盘文件占用",
Long: "分析nfts磁盘文件占用", Long: "分析nfts磁盘文件占用",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if !staros.IsRoot() {
starlog.Criticalln("need administator permission to run this command")
os.Exit(1)
}
if len(args) == 0 { if len(args) == 0 {
os.Exit(folderSize("./")) os.Exit(folderSize("./"))
} }

@ -29,6 +29,10 @@ var Cmd = &cobra.Command{
Short: "查找nfts磁盘文件", Short: "查找nfts磁盘文件",
Long: "查找nfts磁盘文件", Long: "查找nfts磁盘文件",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if !staros.IsRoot() {
starlog.Criticalln("need administator permission to run this command")
os.Exit(1)
}
os.Exit(fileFinder(dfpath, dfreg, dfonlyname, dfoutpath, dfshow)) os.Exit(fileFinder(dfpath, dfreg, dfonlyname, dfoutpath, dfshow))
}, },
} }

@ -0,0 +1,72 @@
package dns
import (
"b612.me/starlog"
"fmt"
"github.com/spf13/cobra"
"os"
"strings"
)
var dnsServer, serverType, queryType string
func init() {
Cmd.Flags().StringVarP(&dnsServer, "server", "s", "", "dns服务器地址")
Cmd.Flags().StringVarP(&serverType, "type", "t", "udp", "dns服务器类型,支持udp,tcp,dot,doh")
Cmd.Flags().StringVarP(&queryType, "query-type", "q", "A", "dns查询类型支持 A,CNAME,AAAA,MX,NS,SOA,SRV,PTR,ANY,CAA,TLSA,DS,DNSKEY,NSEC,NSEC3,NSEC3PARAM,RRSIG,SPF,SSHFP,TKEY,TSIG,URI")
}
var Cmd = &cobra.Command{
Use: "dns",
Short: "dns查询服务",
Long: "DNS查询服务支持UDP,TCP,DoT,DoH",
Run: func(cmd *cobra.Command, args []string) {
itype := 0
switch strings.ToLower(serverType) {
case "udp", "":
itype = 0
case "tcp":
itype = 1
case "dot":
itype = 2
case "doh":
itype = 3
default:
starlog.Errorln("unsupport server type:", serverType)
os.Exit(1)
}
if dnsServer == "" {
switch itype {
case 0, 1:
dnsServer = "223.5.5.5:53"
case 2:
dnsServer = "dns.b612.me:853"
case 3:
dnsServer = "https://dns.b612.me/dns-query"
}
}
if (itype == 0 || itype == 1) && !strings.Contains(dnsServer, ":") {
dnsServer = dnsServer + ":53"
}
if len(args) == 0 {
starlog.Errorln("请输入查询目标")
return
}
queryType = strings.ToUpper(queryType)
fmt.Println("dns服务器:", dnsServer)
fmt.Println("查询类型:", queryType)
for _, target := range args {
data, err := QueryDns(target, queryType, itype, dnsServer)
if err != nil {
starlog.Errorln(err)
os.Exit(2)
}
fmt.Println("\n")
fmt.Println("Query:", target)
for _, v := range data {
fmt.Printf("%s\tRTT=%v\n", v.Res, v.Rtt)
}
}
},
}

@ -0,0 +1,178 @@
package dns
import (
"encoding/base64"
"errors"
"github.com/miekg/dns"
"io"
"net"
"net/http"
"time"
)
type Result struct {
Res string
Type string
Alias string
Rtt int64
}
type DnsClient interface {
Exchange(req *dns.Msg, address string) (r *dns.Msg, rtt time.Duration, err error)
}
func QueryDns(domain string, queryType string, serverType int, dnsServer string) ([]Result, error) {
var c DnsClient
c = new(dns.Client)
m := new(dns.Msg)
if dnsServer == "" {
dnsServer = "223.5.5.5:53"
}
switch serverType {
case 1:
c.(*dns.Client).Net = "tcp"
case 2:
c = &dns.Client{
Net: "tcp-tls",
Dialer: &net.Dialer{
Resolver: net.DefaultResolver,
},
}
case 3:
c = NewDoHClient(WithTimeout(10 * time.Second))
}
var res []Result
switch queryType {
case "A":
m.SetQuestion(dns.Fqdn(domain), dns.TypeA)
case "CNAME":
m.SetQuestion(dns.Fqdn(domain), dns.TypeCNAME)
case "MX":
m.SetQuestion(dns.Fqdn(domain), dns.TypeMX)
case "NS":
m.SetQuestion(dns.Fqdn(domain), dns.TypeNS)
case "TXT":
m.SetQuestion(dns.Fqdn(domain), dns.TypeTXT)
case "SOA":
m.SetQuestion(dns.Fqdn(domain), dns.TypeSOA)
case "SRV":
m.SetQuestion(dns.Fqdn(domain), dns.TypeSRV)
case "AAAA":
m.SetQuestion(dns.Fqdn(domain), dns.TypeAAAA)
case "PTR":
m.SetQuestion(dns.Fqdn(domain), dns.TypePTR)
case "ANY":
m.SetQuestion(dns.Fqdn(domain), dns.TypeANY)
case "CAA":
m.SetQuestion(dns.Fqdn(domain), dns.TypeCAA)
case "TLSA":
m.SetQuestion(dns.Fqdn(domain), dns.TypeTLSA)
case "DS":
m.SetQuestion(dns.Fqdn(domain), dns.TypeDS)
case "DNSKEY":
m.SetQuestion(dns.Fqdn(domain), dns.TypeDNSKEY)
case "NSEC":
m.SetQuestion(dns.Fqdn(domain), dns.TypeNSEC)
case "NSEC3":
m.SetQuestion(dns.Fqdn(domain), dns.TypeNSEC3)
case "NSEC3PARAM":
m.SetQuestion(dns.Fqdn(domain), dns.TypeNSEC3PARAM)
case "RRSIG":
m.SetQuestion(dns.Fqdn(domain), dns.TypeRRSIG)
case "SPF":
m.SetQuestion(dns.Fqdn(domain), dns.TypeSPF)
case "SSHFP":
m.SetQuestion(dns.Fqdn(domain), dns.TypeSSHFP)
case "TKEY":
m.SetQuestion(dns.Fqdn(domain), dns.TypeTKEY)
case "TSIG":
m.SetQuestion(dns.Fqdn(domain), dns.TypeTSIG)
case "URI":
m.SetQuestion(dns.Fqdn(domain), dns.TypeURI)
default:
return nil, errors.New("not support query type,only support A,CNAME,MX,NS,SOA,SRV,AAAA,PTR,ANY,CAA,TLSA,DS,DNSKEY,NSEC,NSEC3,NSEC3PARAM,RRSIG,SPF,SSHFP,TKEY,TSIG,URI")
}
r, rtt, err := c.Exchange(m, dnsServer)
if err != nil {
return nil, err
}
for _, ans := range r.Answer {
res = append(res, Result{Res: ans.String(), Type: queryType, Rtt: rtt.Milliseconds()})
}
return res, nil
}
const DoHMediaType = "application/dns-message"
type clientOptions struct {
Timeout time.Duration // Timeout for one DNS query
}
type ClientOption func(*clientOptions) error
func WithTimeout(t time.Duration) ClientOption {
return func(o *clientOptions) error {
o.Timeout = t
return nil
}
}
type DoHClient struct {
opt *clientOptions
cli *http.Client
}
func NewDoHClient(opts ...ClientOption) *DoHClient {
o := new(clientOptions)
for _, f := range opts {
f(o)
}
return &DoHClient{
opt: o,
cli: &http.Client{
Timeout: o.Timeout,
},
}
}
func (c *DoHClient) Exchange(req *dns.Msg, address string) (r *dns.Msg, rtt time.Duration, err error) {
var (
buf, b64 []byte
begin = time.Now()
origID = req.Id
)
// Set DNS ID as zero accoreding to RFC8484 (cache friendly)
req.Id = 0
buf, err = req.Pack()
b64 = make([]byte, base64.RawURLEncoding.EncodedLen(len(buf)))
if err != nil {
return
}
base64.RawURLEncoding.Encode(b64, buf)
// No need to use hreq.URL.Query()
hreq, _ := http.NewRequest("GET", address+"?dns="+string(b64), nil)
hreq.Header.Add("Accept", DoHMediaType)
resp, err := c.cli.Do(hreq)
if err != nil {
return
}
defer resp.Body.Close()
content, err := io.ReadAll(resp.Body)
if err != nil {
return
}
if resp.StatusCode != http.StatusOK {
err = errors.New("DoH query failed: " + string(content))
return
}
r = new(dns.Msg)
err = r.Unpack(content)
r.Id = origID
rtt = time.Since(begin)
return
}

@ -0,0 +1,17 @@
package dns
import (
"fmt"
"testing"
)
func TestDefaultDns(t *testing.T) {
p, e := QueryDns("google.com", "A", 3, "https://dns.b612.me/dns-query")
if e != nil {
t.Error(e)
}
for _, v := range p {
fmt.Printf("%+v\n", v)
}
}

@ -3,34 +3,38 @@ module b612.me/apps/b612
go 1.19 go 1.19
require ( require (
b612.me/notify v1.2.4 b612.me/notify v1.2.5
b612.me/starcrypto v0.0.2 b612.me/starcrypto v0.0.4
b612.me/stario v0.0.8 b612.me/stario v0.0.9
b612.me/starlog v1.3.2 b612.me/starlog v1.3.3
b612.me/staros v1.1.6 b612.me/staros v1.1.7
b612.me/starssh v0.0.2 b612.me/starssh v0.0.2
b612.me/startext v0.0.0-20220314043758-22c6d5e5b1cd b612.me/startext v0.0.0-20220314043758-22c6d5e5b1cd
b612.me/wincmd v0.0.2 b612.me/wincmd v0.0.3
github.com/goftp/file-driver v0.0.0-20180502053751-5d604a0fc0c9 github.com/goftp/file-driver v0.0.0-20180502053751-5d604a0fc0c9
github.com/goftp/server v0.0.0-20200708154336-f64f7c2d8a42 github.com/goftp/server v0.0.0-20200708154336-f64f7c2d8a42
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/inconshreveable/mousetrap v1.0.1 github.com/inconshreveable/mousetrap v1.1.0
github.com/miekg/dns v1.1.58
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
github.com/spf13/cobra v1.6.1 github.com/spf13/cobra v1.8.0
) )
require ( require (
b612.me/starmap v1.2.3 // indirect b612.me/starmap v1.2.4 // indirect
b612.me/starnet v0.1.7 // indirect b612.me/starnet v0.1.8 // indirect
b612.me/win32api v0.0.1 // indirect b612.me/win32api v0.0.2 // indirect
github.com/jlaffaye/ftp v0.1.0 // indirect github.com/jlaffaye/ftp v0.1.0 // indirect
github.com/kr/fs v0.1.0 // indirect github.com/kr/fs v0.1.0 // indirect
github.com/pkg/sftp v1.13.4 // indirect github.com/pkg/sftp v1.13.4 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.8.0 // indirect github.com/stretchr/testify v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect golang.org/x/crypto v0.21.0 // indirect
golang.org/x/image v0.6.0 // indirect golang.org/x/image v0.6.0 // indirect
golang.org/x/sys v0.5.0 // indirect golang.org/x/mod v0.14.0 // indirect
golang.org/x/term v0.5.0 // indirect golang.org/x/net v0.21.0 // indirect
golang.org/x/text v0.8.0 // indirect golang.org/x/sys v0.18.0 // indirect
golang.org/x/term v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.17.0 // indirect
) )

@ -1,27 +1,27 @@
b612.me/notify v1.2.4 h1:cjP80V9FeM+ib1DztZdykusakcbjNI4dAB1pXE8U6bo= b612.me/notify v1.2.5 h1:fASpzi8YAo78g6jKnefzfbsQz0nGNYFbClB2Bylj+MA=
b612.me/notify v1.2.4/go.mod h1:SlCrG1kPRVhYUrIkwY/j0zAwCU4VeTHubcZoQXW8Anw= b612.me/notify v1.2.5/go.mod h1:GTnAdC6v9krGxtC8Gkn8TcyUsYnHSiHjRAXsONPiLpI=
b612.me/starcrypto v0.0.2 h1:aRf1HcqK8GqHYxLAhWfFC4W/EqQLEFNEmxsBu3wG30o= b612.me/starcrypto v0.0.3/go.mod h1:pF5A16p8r/h1G0x7ZNmmAF6K1sdIMpbCUxn2WGC8gZ0=
b612.me/starcrypto v0.0.2/go.mod h1:hz0xRnfWNpYOlVrIPoGrQOWPibq4YiUZ7qN5tsQbzPo= b612.me/starcrypto v0.0.4 h1:4obj3QC9SoFop9WA3xKNS99WCvRrxZnvEUMBVzrD4HM=
b612.me/stario v0.0.7/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw= b612.me/starcrypto v0.0.4/go.mod h1:pF5A16p8r/h1G0x7ZNmmAF6K1sdIMpbCUxn2WGC8gZ0=
b612.me/stario v0.0.8 h1:kaA4pszAKLZJm2D9JmiuYSpgjTeE3VaO74vm+H0vBGM= b612.me/stario v0.0.9 h1:bFDlejUJMwZ12a09snZJspQsOlkqpDAl9qKPEYOGWCk=
b612.me/stario v0.0.8/go.mod h1:or4ssWcxQSjMeu+hRKEgtp0X517b3zdlEOAms8Qscvw= b612.me/stario v0.0.9/go.mod h1:x4D/x8zA5SC0pj/uJAi4FyG5p4j5UZoMEZfvuRR6VNw=
b612.me/starlog v1.3.2 h1:bFUJyZEpcOcBwPlzlhPBwlYxq7aDcR8pJNoaDk+SUNE= b612.me/starlog v1.3.3 h1:xYCHouOTpo6dsFg2A92TqTznxvRPPS/ovMWs7CJZ9WI=
b612.me/starlog v1.3.2/go.mod h1:bxSvBSzlJoLfrZJ5b9CJFuQaXjFi8PYUbGWitNO1FYA= b612.me/starlog v1.3.3/go.mod h1:h928hRahvWqcXXxy0uKWZ+oFe3K7kFQDHKiBemedLyE=
b612.me/starmap v1.2.3 h1:+ao++KgbSGMA4UzcHm/EXJoukbUudk8t5ac7rjwV9KA= b612.me/starmap v1.2.4 h1:gfAyBtzW3KKCIyI14I2pEqGsR/u2E+3tkH0xRqtWb4E=
b612.me/starmap v1.2.3/go.mod h1:K+exTSWg8i/taoUyGR6DPW6Ja0k6aIdpcniqByOf4O0= b612.me/starmap v1.2.4/go.mod h1:EhOUzkItc5IcyBmr1C7/vmZBbW3GgCWs63hGn7WhuMc=
b612.me/starnet v0.1.7 h1:k3CUfYNRolC/xw5Ekus2NVWHlqeykSyAH8USGTPKA5o= b612.me/starnet v0.1.8 h1:sTNytUFP38i2BFR9nha3lTSLYb7El3tvKpZplYCrhZk=
b612.me/starnet v0.1.7/go.mod h1:DNC4i/ezgVLlmxnquf8AeljsL4mQ5vAyxh8vGPQqsys= b612.me/starnet v0.1.8/go.mod h1:k862Kf8DiVWTqdX6PHTFb6NoT+3G3Y74n8NCyNhuP0Y=
b612.me/staros v1.1.6 h1:m3QaEmPyvPcJVomjWs8cDeauDYFNKv7cLHTiOHClKqM= b612.me/staros v1.1.7 h1:GkQp5sBPRqo3pOh6nKyKffJydyYrjlfzpsPxNeVJ26g=
b612.me/staros v1.1.6/go.mod h1:O657LC3qag4VSsHNmt5RM8gKJvzoEGq8IF8WegcRgq0= b612.me/staros v1.1.7/go.mod h1:Yi/WfvIqRAPQEf/eiaaIwrL5LNcUbqzMIuFIyJJOU40=
b612.me/starssh v0.0.2 h1:cYlrXjd7ZTesdZG+7XcoLsEEMROaeWMTYonScBLnvyY= b612.me/starssh v0.0.2 h1:cYlrXjd7ZTesdZG+7XcoLsEEMROaeWMTYonScBLnvyY=
b612.me/starssh v0.0.2/go.mod h1:1gvG/GT5Y5EvOx9ZKnLFUa+wOX20HaqS1IuTnU7BOlk= b612.me/starssh v0.0.2/go.mod h1:1gvG/GT5Y5EvOx9ZKnLFUa+wOX20HaqS1IuTnU7BOlk=
b612.me/startext v0.0.0-20220314043758-22c6d5e5b1cd h1:EsmnczYZhOV8JTxD/m0N0qBjfZN8JuLNrTJ6z3S8YqA= b612.me/startext v0.0.0-20220314043758-22c6d5e5b1cd h1:EsmnczYZhOV8JTxD/m0N0qBjfZN8JuLNrTJ6z3S8YqA=
b612.me/startext v0.0.0-20220314043758-22c6d5e5b1cd/go.mod h1:yKdeLQHZ3scqyjw1ZODCoL+hLmkOp2eu5riP4agraz8= b612.me/startext v0.0.0-20220314043758-22c6d5e5b1cd/go.mod h1:yKdeLQHZ3scqyjw1ZODCoL+hLmkOp2eu5riP4agraz8=
b612.me/win32api v0.0.1 h1:vLFB1xhO6pd9+zB2EyaapKB459Urv3v+C1YwgwOFEWo= b612.me/win32api v0.0.2 h1:5PwvPR5fYs3a/v+LjYdtRif+5Q04zRGLTVxmCYNjCpA=
b612.me/win32api v0.0.1/go.mod h1:MHu0JBQjzxQ2yxpZPUBbn5un45o67eF5iWKa4Q9e0yE= b612.me/win32api v0.0.2/go.mod h1:sj66sFJDKElEjOR+0YhdSW6b4kq4jsXu4T5/Hnpyot0=
b612.me/wincmd v0.0.2 h1:Ub1WtelVT6a3vD4B6zDYo3UPO/t9ymnI3x1dQPJcrGw= b612.me/wincmd v0.0.3 h1:GYrkYnNun39yfNcA2+u0h4VW/BYbTrJK39QW4W1LCYA=
b612.me/wincmd v0.0.2/go.mod h1:bwpyCKfSDY8scSMo3Lrd0Qnqvpz7/CILL7oodfG0wgo= b612.me/wincmd v0.0.3/go.mod h1:nWdNREHO6F+2PngEUcyYN3Eo7DzYEVa/fO6czd9d/fo=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@ -33,12 +33,14 @@ github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jlaffaye/ftp v0.1.0 h1:DLGExl5nBoSFoNshAUHwXAezXwXBvFdx7/qwhucWNSE= github.com/jlaffaye/ftp v0.1.0 h1:DLGExl5nBoSFoNshAUHwXAezXwXBvFdx7/qwhucWNSE=
github.com/jlaffaye/ftp v0.1.0/go.mod h1:hhq4G4crv+nW2qXtNYcuzLeOudG92Ps37HEKeg2e3lE= github.com/jlaffaye/ftp v0.1.0/go.mod h1:hhq4G4crv+nW2qXtNYcuzLeOudG92Ps37HEKeg2e3lE=
github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8= github.com/kr/fs v0.1.0 h1:Jskdu9ieNAYnjxsi0LbQp1ulIKZV1LAFgK1tWhpZgl8=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/miekg/dns v1.1.58 h1:ca2Hdkz+cDg/7eNF6V56jjzuZ4aCAE+DbVkILdQWG/4=
github.com/miekg/dns v1.1.58/go.mod h1:Ypv+3b/KadlvW9vJfXOTf300O4UqaHFzFCuHz+rPkBY=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8= github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/pkg/sftp v1.13.4 h1:Lb0RYJCmgUcBgZosfoi9Y9sbl6+LJgOIgk/2Y4YjMFg= github.com/pkg/sftp v1.13.4 h1:Lb0RYJCmgUcBgZosfoi9Y9sbl6+LJgOIgk/2Y4YjMFg=
@ -46,8 +48,8 @@ github.com/pkg/sftp v1.13.4/go.mod h1:LzqnAvaD5TWeNBsZpfKxSYn1MbjWwOsCIAFFJbpIsK
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.6.1 h1:o94oiPyS4KD1mPy2fmcYYHHfCxLqYjJOhGsCHFZtEzA= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.6.1/go.mod h1:IOw/AERYS7UzyrGinqmz6HLUo219MORXGxhbaJUqzrY= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
@ -61,46 +63,61 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220313003712-b769efc7c000/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s= golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4= golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4=
golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0 h1:57P1ETyNKtuIjB4SRd15iJxuhj8Gc416Y78H3qgMh68=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc=
golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

@ -45,6 +45,11 @@ func MergePhoto(big, small image.Image, bigsize, smallsize uint, x, y int) image
return nimg return nimg
} }
func CompressPhoto(pho image.Image) image.Image {
//b := pho.Bounds()
return resize.Resize(0, 0, pho, resize.Bilinear)
}
func SavePhoto(path string, img image.Image) error { func SavePhoto(path string, img image.Image) error {
imgf, err := os.Create(path) imgf, err := os.Create(path)
if err != nil { if err != nil {

@ -0,0 +1,15 @@
package image
import "testing"
func TestCompressPhoto(t *testing.T) {
p, err := OpenImage("../bin/original.jpg")
if err != nil {
t.Error(err)
}
p = CompressPhoto(p)
err = SavePhoto("../bin/compressed.jpg", p)
if err != nil {
t.Error(err)
}
}

@ -0,0 +1,104 @@
package keygen
import (
"b612.me/starcrypto"
"b612.me/starlog"
"b612.me/staros"
"github.com/spf13/cobra"
"os"
"time"
)
var k KeyGen
var startdate string
var duration int
var secret string
var path string
var key string
var outpath string
func init() {
Cmd.Flags().StringVarP(&k.Type, "type", "t", "rsa", "Key Type: rsa, ecdsa")
Cmd.Flags().StringVarP(&k.Encrypt, "encrypt", "e", "", "Encrypt Key with Password (not recommended)")
Cmd.Flags().IntVarP(&k.Bits, "bits", "b", 2048, "Key Bits Rsa: 1024, 2048, 4096 Ecdsa: 224, 256, 384, 521")
Cmd.Flags().StringVarP(&k.Prefix, "prefix", "p", "mykey", "Output File Prefix")
Cmd.Flags().StringVarP(&k.Outfolder, "outfolder", "o", ".", "Output Folder")
Cmd.Flags().BoolVarP(&k.Force, "force", "f", false, "Force Overwrite")
Cmd.Flags().StringVarP(&k.Country, "country", "c", "CN", "Country")
Cmd.Flags().StringVarP(&k.Locality, "locality", "l", "Beijing", "Locality")
Cmd.Flags().StringVarP(&k.Organization, "organization", "O", "B612", "Organization")
Cmd.Flags().StringVarP(&k.OrganizationalUnit, "organizationalunit", "U", "B612", "OrganizationalUnit")
Cmd.Flags().StringVarP(&k.CommonName, "commonname", "C", "Little Prince", "CommonName")
Cmd.Flags().StringVarP(&startdate, "startdate", "s", "", "Cert Start Date")
Cmd.Flags().IntVarP(&duration, "duration", "d", 3650, "Cert Duration")
CmdEn.Flags().StringVarP(&secret, "secret", "s", "", "new Private Key Password,if empty,disable password")
CmdEn.Flags().StringVarP(&path, "path", "p", "", "private key file path")
CmdEn.Flags().StringVarP(&key, "key", "k", "", "private key old password,if empty,disable password")
CmdEn.Flags().StringVarP(&outpath, "outpath", "o", "./newkey", "new key file output path")
Cmd.AddCommand(CmdEn)
}
var Cmd = &cobra.Command{
Use: "keygen",
Short: "keygen",
Long: "keygen",
Run: func(cmd *cobra.Command, args []string) {
var err error
if startdate != "" {
k.StartDate, err = time.Parse("2006-01-02", startdate)
if err != nil {
starlog.Errorln(err)
os.Exit(1)
}
} else {
k.StartDate = time.Now()
}
if duration < 0 {
starlog.Errorln("duration should be positive")
os.Exit(1)
}
k.EndDate = k.StartDate.AddDate(0, 0, duration)
err = k.Gen()
if err != nil {
starlog.Errorln(err)
os.Exit(1)
}
starlog.Infoln("Key Generated,Ouput to", k.Outfolder)
},
}
var CmdEn = &cobra.Command{
Use: "pwd",
Short: "encrypt/change private key",
Run: func(cmd *cobra.Command, args []string) {
if !staros.Exists(path) {
starlog.Errorln("file not exists")
os.Exit(1)
}
data, err := os.ReadFile(path)
if err != nil {
starlog.Errorln("read file error:", err)
os.Exit(1)
}
priv, err := starcrypto.DecodePrivateKey(data, key)
if err != nil {
starlog.Errorln("decode private key error:", err)
os.Exit(1)
}
data, err = starcrypto.EncodePrivateKey(priv, secret)
if err != nil {
starlog.Errorln("encode private key error:", err)
os.Exit(1)
}
err = os.WriteFile(outpath, data, 0644)
if err != nil {
starlog.Errorln("write new file error:", err)
os.Exit(1)
}
starlog.Infoln("new key saved to", outpath)
},
}

@ -0,0 +1,195 @@
package keygen
import (
"b612.me/starcrypto"
"b612.me/staros"
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/hex"
"encoding/pem"
"errors"
"io"
"math/big"
"os"
"path/filepath"
"strings"
"time"
)
type KeyGen struct {
Type string
Encrypt string
Bits int
Outfolder string
Prefix string
Force bool
//
Country string
Locality string
Organization string
OrganizationalUnit string
CommonName string
StartDate time.Time
EndDate time.Time
}
func (k *KeyGen) Gen() error {
if !k.Force && staros.Exists(filepath.Join(k.Outfolder, k.Prefix+".crt")) {
return errors.New("crt file exists")
}
if !k.Force && staros.Exists(filepath.Join(k.Outfolder, k.Prefix)) {
return errors.New("key file exists")
}
if !k.Force && staros.Exists(filepath.Join(k.Outfolder, k.Prefix+".pub")) {
return errors.New("ssh pub file exists")
}
if !k.Force && staros.Exists(filepath.Join(k.Outfolder, k.Prefix+".key.pub")) {
return errors.New("pub file exists")
}
var sshPubByte, keyPubByte, keyPrivByte, Crt []byte
var priv, pub any
var err error
switch strings.ToLower(k.Type) {
case "rsa":
priv, pub, err = starcrypto.GenerateRsaKey(k.Bits)
if err != nil {
return err
}
case "ecdsa":
var cr elliptic.Curve
switch k.Bits {
case 224:
cr = elliptic.P224()
case 256:
cr = elliptic.P256()
case 384:
cr = elliptic.P384()
case 521:
cr = elliptic.P521()
default:
return errors.New("invalid bits,should be 224,256,384,521")
}
priv, pub, err = starcrypto.GenerateEcdsaKey(cr)
if err != nil {
return err
}
default:
return errors.New("invalid key type,only support rsa,ecdsa")
}
sshPubByte, err = starcrypto.EncodeSSHPublicKey(pub)
if err != nil {
return err
}
keyPubByte, err = starcrypto.EncodePublicKey(pub)
if err != nil {
return err
}
keyPrivByte, err = starcrypto.EncodePrivateKey(priv, k.Encrypt)
if err != nil {
return err
}
_, Crt, err = k.GenerateCert(priv)
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(k.Outfolder, k.Prefix+".crt"), Crt, 0644)
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(k.Outfolder, k.Prefix), keyPrivByte, 0644)
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(k.Outfolder, k.Prefix+".pub"), sshPubByte, 0644)
if err != nil {
return err
}
err = os.WriteFile(filepath.Join(k.Outfolder, k.Prefix+".key.pub"), keyPubByte, 0644)
if err != nil {
return err
}
return nil
}
func (k *KeyGen) GenerateCert(priv crypto.PrivateKey) ([]byte, []byte, error) {
//csr,pub
tmpByte := make([]byte, 64)
io.ReadFull(rand.Reader, tmpByte)
hexStr := starcrypto.String(tmpByte)
data, _ := hex.DecodeString(hexStr)
num := new(big.Int).SetBytes(data)
var country, locality, organization, organizationalUnit []string
if k.Country != "" {
country = []string{k.Country}
}
if k.Locality != "" {
locality = []string{k.Locality}
}
if k.Organization != "" {
organization = []string{k.Organization}
}
if k.OrganizationalUnit != "" {
organizationalUnit = []string{k.OrganizationalUnit}
}
var rootCsr = &x509.Certificate{
Version: 3,
SerialNumber: num,
Subject: pkix.Name{
Country: country,
Locality: locality,
Organization: organization,
OrganizationalUnit: organizationalUnit,
CommonName: k.CommonName,
},
NotBefore: k.StartDate,
NotAfter: k.EndDate,
BasicConstraintsValid: true,
IsCA: false,
MaxPathLenZero: false,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageAny},
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign | x509.KeyUsageKeyEncipherment | x509.KeyUsageKeyAgreement | x509.KeyUsageDigitalSignature,
}
var cert []byte
var err error
switch priv.(type) {
case *rsa.PrivateKey:
cert, err = MakeCert(priv.(*rsa.PrivateKey), rootCsr, rootCsr, priv.(*rsa.PrivateKey).Public())
if err != nil {
return nil, nil, err
}
case *ecdsa.PrivateKey:
cert, err = MakeCert(priv.(*ecdsa.PrivateKey), rootCsr, rootCsr, priv.(*ecdsa.PrivateKey).Public())
default:
return nil, nil, errors.New("invalid private key type")
}
csrPem := pem.EncodeToMemory(&pem.Block{
Type: "CERTIFICATE REQUEST",
Bytes: rootCsr.Raw,
})
return csrPem, cert, nil
}
func MakeCert(caKey any, caCrt *x509.Certificate, csr *x509.Certificate, pub any) ([]byte, error) {
der, err := x509.CreateCertificate(rand.Reader, csr, caCrt, pub, caKey)
if err != nil {
return nil, err
}
cert, err := x509.ParseCertificate(der)
if err != nil {
return nil, err
}
certBlock := &pem.Block{
Type: "CERTIFICATE",
Bytes: cert.Raw,
}
pemData := pem.EncodeToMemory(certBlock)
return pemData, nil
}

@ -0,0 +1,25 @@
package keygen
import (
"testing"
)
func TestKeyGen_Gen(t *testing.T) {
var k = KeyGen{
Type: "rsa",
Encrypt: "",
Bits: 2048,
Outfolder: ".",
Prefix: "mykey",
Force: true,
Country: "CN",
Locality: "Beijing",
Organization: "B612",
OrganizationalUnit: "B612",
CommonName: "Little Prince",
}
err := k.Gen()
if err != nil {
t.Error(err)
}
}

@ -9,14 +9,17 @@ import (
"b612.me/apps/b612/detach" "b612.me/apps/b612/detach"
"b612.me/apps/b612/df" "b612.me/apps/b612/df"
"b612.me/apps/b612/dfinder" "b612.me/apps/b612/dfinder"
"b612.me/apps/b612/dns"
"b612.me/apps/b612/ftp" "b612.me/apps/b612/ftp"
"b612.me/apps/b612/generate" "b612.me/apps/b612/generate"
"b612.me/apps/b612/hash" "b612.me/apps/b612/hash"
"b612.me/apps/b612/httpreverse" "b612.me/apps/b612/httpreverse"
"b612.me/apps/b612/httpserver" "b612.me/apps/b612/httpserver"
"b612.me/apps/b612/image" "b612.me/apps/b612/image"
"b612.me/apps/b612/keygen"
"b612.me/apps/b612/merge" "b612.me/apps/b612/merge"
"b612.me/apps/b612/net" "b612.me/apps/b612/net"
"b612.me/apps/b612/rmt"
"b612.me/apps/b612/search" "b612.me/apps/b612/search"
"b612.me/apps/b612/split" "b612.me/apps/b612/split"
"b612.me/apps/b612/tcping" "b612.me/apps/b612/tcping"
@ -30,7 +33,7 @@ import (
var cmdRoot = &cobra.Command{ var cmdRoot = &cobra.Command{
Use: "b612", Use: "b612",
Version: "2.0.2", Version: "2.1.0",
} }
func init() { func init() {
@ -38,7 +41,7 @@ func init() {
cmdRoot.AddCommand(tcping.Cmd, uac.Cmd, httpserver.Cmd, httpreverse.Cmd, cmdRoot.AddCommand(tcping.Cmd, uac.Cmd, httpserver.Cmd, httpreverse.Cmd,
base64.Cmd, base85.Cmd, base91.Cmd, attach.Cmd, detach.Cmd, df.Cmd, dfinder.Cmd, base64.Cmd, base85.Cmd, base91.Cmd, attach.Cmd, detach.Cmd, df.Cmd, dfinder.Cmd,
ftp.Cmd, generate.Cmd, hash.Cmd, image.Cmd, merge.Cmd, search.Cmd, split.Cmd, vic.Cmd, ftp.Cmd, generate.Cmd, hash.Cmd, image.Cmd, merge.Cmd, search.Cmd, split.Cmd, vic.Cmd,
calc.Cmd, net.Cmd) calc.Cmd, net.Cmd, rmt.Cmds, rmt.Cmdc, keygen.Cmd, dns.Cmd)
} }
func main() { func main() {

@ -1 +0,0 @@
package ping

@ -18,13 +18,14 @@ import (
var stFolder string var stFolder string
var stNum, stMax, stMin int var stNum, stMax, stMin int
var stautoGBK, allowEmoji bool var stautoGBK, allowEmoji, onlyShowFileName bool
func init() { func init() {
Cmd.Flags().StringVarP(&stFolder, "folder", "f", "./", "搜索的文件夹") Cmd.Flags().StringVarP(&stFolder, "folder", "f", "./", "搜索的文件夹")
Cmd.Flags().IntVarP(&stNum, "thread-num", "n", 5, "并发搜寻协程数") Cmd.Flags().IntVarP(&stNum, "thread-num", "n", 5, "并发搜寻协程数")
Cmd.Flags().BoolVarP(&allowEmoji, "allow-emoji", "e", false, "使用\\U输入Emoji") Cmd.Flags().BoolVarP(&allowEmoji, "allow-emoji", "e", false, "使用\\U输入Emoji")
Cmd.Flags().BoolVarP(&stautoGBK, "autogbk", "g", true, "自动GBK识别") Cmd.Flags().BoolVarP(&stautoGBK, "autogbk", "g", false, "自动GBK识别")
Cmd.Flags().BoolVarP(&onlyShowFileName, "only-show-filename", "o", false, "只显示文件名")
Cmd.Flags().IntVar(&stMax, "max", 0, "行最大字数") Cmd.Flags().IntVar(&stMax, "max", 0, "行最大字数")
Cmd.Flags().IntVar(&stMin, "min", 0, "行最小字数") Cmd.Flags().IntVar(&stMin, "min", 0, "行最小字数")
} }
@ -41,7 +42,7 @@ var Cmd = &cobra.Command{
if allowEmoji { if allowEmoji {
args[1], _ = replaceUnicodeEmoji(args[1]) args[1], _ = replaceUnicodeEmoji(args[1])
} }
err := searchText(stFolder, args[0], args[1], stNum, stautoGBK, stMax, stMin) err := searchText(stFolder, args[0], args[1], stNum, stautoGBK, stMax, stMin, onlyShowFileName)
if err != nil { if err != nil {
os.Exit(2) os.Exit(2)
} }
@ -95,7 +96,7 @@ func unicodeToEmoji(codepoint string) (string, error) {
return emoji, nil return emoji, nil
} }
func searchText(folder string, filematch string, text string, thread int, autoGBK bool, max, min int) error { func searchText(folder string, filematch string, text string, thread int, autoGBK bool, max, min int, onlyShowFileName bool) error {
data, err := ioutil.ReadDir(folder) data, err := ioutil.ReadDir(folder)
if err != nil { if err != nil {
starlog.Errorln("read folder failed", folder, err) starlog.Errorln("read folder failed", folder, err)
@ -128,7 +129,11 @@ func searchText(folder string, filematch string, text string, thread int, autoGB
continue continue
} }
if strings.Contains(origin, text) { if strings.Contains(origin, text) {
fmt.Printf("file:%s line:%d matched:%s\n", filepath, count, origin) if !onlyShowFileName {
fmt.Printf("file:%s line:%d matched:%s\n", filepath, count, origin)
} else {
fmt.Printf("file:%s line:%d\n", filepath, count)
}
} }
if err != nil { if err != nil {
break break
@ -137,7 +142,7 @@ func searchText(folder string, filematch string, text string, thread int, autoGB
} }
for _, v := range data { for _, v := range data {
if v.IsDir() { if v.IsDir() {
searchText(filepath.Join(folder, v.Name()), filematch, text, thread, autoGBK, stMax, stMin) searchText(filepath.Join(folder, v.Name()), filematch, text, thread, autoGBK, stMax, stMin, onlyShowFileName)
} }
filepath := filepath.Join(folder, v.Name()) filepath := filepath.Join(folder, v.Name())
if matched, _ := regexp.MatchString(filematch, filepath); matched { if matched, _ := regexp.MatchString(filematch, filepath); matched {

@ -28,16 +28,16 @@ var (
var Cmd = &cobra.Command{ var Cmd = &cobra.Command{
Use: "tcping", Use: "tcping",
Short: "tcp/http ping", Short: "tcp/http dns",
Long: "使用进行Tcp或Http协议进行ping探测", Long: "使用进行Tcp或Http协议进行ping探测",
Example: ` Example: `
1. ping over tcp 1. dns over tcp
> tcping google.com > tcping google.com
2. ping over tcp with custom port 2. dns over tcp with custom port
> tcping google.com 443 > tcping google.com 443
3. ping over http 3. dns over http
> tcping -H google.com > tcping -H google.com
4. ping with URI schema 4. dns with URI schema
> tcping http://hui.lu > tcping http://hui.lu
`, `,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {

@ -36,7 +36,7 @@ func (ping *HTTPing) SetTarget(target *Target) {
} }
} }
// Start ping // Start dns
func (ping *HTTPing) Start() <-chan struct{} { func (ping *HTTPing) Start() <-chan struct{} {
go func() { go func() {
t := time.NewTicker(ping.target.Interval) t := time.NewTicker(ping.target.Interval)
@ -79,7 +79,7 @@ func (ping *HTTPing) Start() <-chan struct{} {
return ping.done return ping.done
} }
// Result return ping result // Result return dns result
func (ping *HTTPing) Result() *Result { func (ping *HTTPing) Result() *Result {
return ping.result return ping.result
} }

@ -47,7 +47,7 @@ func NewProtocol(protocol string) (Protocol, error) {
return 0, fmt.Errorf("protocol %s not support", protocol) return 0, fmt.Errorf("protocol %s not support", protocol)
} }
// Target is a ping // Target is a dns
type Target struct { type Target struct {
Protocol Protocol Protocol Protocol
Host string Host string
@ -62,7 +62,7 @@ func (target Target) String() string {
return fmt.Sprintf("%s://%s:%d", target.Protocol, target.Host, target.Port) return fmt.Sprintf("%s://%s:%d", target.Protocol, target.Host, target.Port)
} }
// Pinger is a ping interface // Pinger is a dns interface
type Pinger interface { type Pinger interface {
Start() <-chan struct{} Start() <-chan struct{}
Stop() Stop()
@ -70,7 +70,7 @@ type Pinger interface {
SetTarget(target *Target) SetTarget(target *Target)
} }
// Ping is a ping interface // Ping is a dns interface
type Ping interface { type Ping interface {
Start() <-chan struct{} Start() <-chan struct{}
@ -95,7 +95,7 @@ type Result struct {
TotalDuration time.Duration TotalDuration time.Duration
} }
// Avg return the average time of ping // Avg return the average time of dns
func (result Result) Avg() time.Duration { func (result Result) Avg() time.Duration {
if result.SuccessCounter == 0 { if result.SuccessCounter == 0 {
return 0 return 0

Loading…
Cancel
Save