Init nagato
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -15,3 +15,4 @@
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
nagato
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
# nagato
|
||||
|
||||
https://myanimelist.net/character/249/Yuki_Nagato
|
||||
https://myanimelist.net/character/249/Yuki_Nagato
|
||||
|
||||
14
go.mod
Normal file
14
go.mod
Normal file
@@ -0,0 +1,14 @@
|
||||
module nagato
|
||||
|
||||
go 1.17
|
||||
|
||||
require (
|
||||
github.com/andybalholm/brotli v1.0.3 // indirect
|
||||
github.com/gookit/color v1.4.2
|
||||
github.com/klauspost/compress v1.13.6 // indirect
|
||||
github.com/valyala/bytebufferpool v1.0.0 // indirect
|
||||
github.com/valyala/fasthttp v1.31.0
|
||||
github.com/valyala/fastjson v1.6.3
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||
golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 // indirect
|
||||
)
|
||||
45
go.sum
Normal file
45
go.sum
Normal file
@@ -0,0 +1,45 @@
|
||||
github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
|
||||
github.com/andybalholm/brotli v1.0.3 h1:fpcw+r1N1h0Poc1F/pHbW40cUm/lMEQslZtCkBQ0UnM=
|
||||
github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/gookit/color v1.4.2 h1:tXy44JFSFkKnELV6WaMo/lLfu/meqITX3iAV52do7lk=
|
||||
github.com/gookit/color v1.4.2/go.mod h1:fqRyamkC1W8uxl+lxCQxOT09l/vYfZ+QeiX3rKQHCoQ=
|
||||
github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
|
||||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
|
||||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
|
||||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasthttp v1.30.0 h1:nBNzWrgZUUHohyLPU/jTvXdhrcaf2m5k3bWk+3Q049g=
|
||||
github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
||||
github.com/valyala/fasthttp v1.31.0 h1:lrauRLII19afgCs2fnWRJ4M5IkV0lo2FqA61uGkNBfE=
|
||||
github.com/valyala/fasthttp v1.31.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
||||
github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc=
|
||||
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210514084401-e8d321eab015/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7 h1:c20P3CcPbopVp2f7099WLOqSNKURf30Z0uq66HpijZY=
|
||||
golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20211015200801-69063c4bb744 h1:KzbpndAYEM+4oHRp9JmB2ewj0NHHxO3Z0g7Gus2O1kk=
|
||||
golang.org/x/sys v0.0.0-20211015200801-69063c4bb744/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
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/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
7
nagato.code-workspace
Normal file
7
nagato.code-workspace
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "."
|
||||
}
|
||||
]
|
||||
}
|
||||
240
nagato.go
Normal file
240
nagato.go
Normal file
@@ -0,0 +1,240 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/gookit/color"
|
||||
"github.com/valyala/fasthttp"
|
||||
"github.com/valyala/fastjson"
|
||||
)
|
||||
|
||||
// IPData Contains IP data
|
||||
type IPData struct {
|
||||
IP string
|
||||
CountryC string
|
||||
Country string
|
||||
RegionC string
|
||||
Region string
|
||||
ContinentC string
|
||||
Continent string
|
||||
City string
|
||||
}
|
||||
|
||||
func main() {
|
||||
retChan := make(chan string)
|
||||
color.Notice.Println("nagato 1.0")
|
||||
|
||||
go runCmd(retChan, "uname", "-a")
|
||||
out := <-retChan
|
||||
color.Notice.Print(runtime.Version() + " " + out)
|
||||
|
||||
// Get status
|
||||
go runCmd(retChan, "nordvpn", "status")
|
||||
out = <-retChan
|
||||
if strings.Contains(out, "Connected") {
|
||||
fmt.Print(out)
|
||||
go runCmd(retChan, "nordvpn", "disconnect")
|
||||
out = <-retChan
|
||||
fmt.Println(out)
|
||||
if !strings.Contains(out, "disconnected") {
|
||||
color.Errorln("nordvpn plz")
|
||||
os.Exit(-1)
|
||||
}
|
||||
} else {
|
||||
if !strings.Contains(out, "Disconnected") {
|
||||
color.Errorln(out)
|
||||
color.Errorln("nordvpn plz")
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
// Set killswitch off
|
||||
go runCmd(retChan, "nordvpn", "set", "killswitch", "off")
|
||||
out = <-retChan
|
||||
fmt.Print(out)
|
||||
if !(strings.Contains(out, "Kill") && strings.Contains(out, "disabled") && (strings.Contains(out, "success") || strings.Contains(out, "already"))) {
|
||||
color.Errorln("nordvpn plz")
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
// check IP
|
||||
go getIP(retChan)
|
||||
out = <-retChan
|
||||
if strings.Contains(out, "ERR") {
|
||||
color.Errorln(out)
|
||||
color.Errorln("Jeff plz")
|
||||
os.Exit(-1)
|
||||
}
|
||||
color.Info.Print(out)
|
||||
ip := out
|
||||
|
||||
// nordvpn connect Switzerland
|
||||
go runCmd(retChan, "nordvpn", "connect", "Switzerland")
|
||||
out = <-retChan
|
||||
fmt.Print(out)
|
||||
if !(strings.Contains(out, "connected") && strings.Contains(out, "Switzerland")) {
|
||||
color.Errorln("nordvpn plz")
|
||||
go runCmd(retChan, "nordvpn", "set", "killswitch", "on")
|
||||
fmt.Println(<-retChan)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
// nordvpn killswitch on
|
||||
go runCmd(retChan, "nordvpn", "set", "killswitch", "on")
|
||||
out = <-retChan
|
||||
fmt.Print(out)
|
||||
if !(strings.Contains(out, "Kill") && strings.Contains(out, "enabled") && strings.Contains(out, "success")) {
|
||||
color.Errorln("nordvpn plz")
|
||||
go runCmd(retChan, "nordvpn", "disconnect")
|
||||
fmt.Println(<-retChan)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
// nordvpn status
|
||||
go runCmd(retChan, "nordvpn", "status")
|
||||
out = <-retChan
|
||||
fmt.Print(out)
|
||||
|
||||
// check connection
|
||||
retDataChan := make(chan IPData)
|
||||
go getIPData(retChan, retDataChan)
|
||||
out = <-retChan
|
||||
if strings.Contains(out, "ERR") {
|
||||
color.Errorln(out)
|
||||
color.Errorln("IPLeak plz")
|
||||
os.Exit(-1)
|
||||
}
|
||||
ipData := <-retDataChan
|
||||
color.Comment.Printf("%v\n", ipData)
|
||||
if strings.Contains(ip, ipData.IP) {
|
||||
color.Danger.Println("IP unchanged")
|
||||
os.Exit(-1)
|
||||
}
|
||||
if strings.Contains(ipData.CountryC, "DE") || strings.Contains(ipData.Country, "Ger") {
|
||||
color.Danger.Println("BRATWURST")
|
||||
os.Exit(-1)
|
||||
}
|
||||
if strings.Contains(ipData.CountryC, "CH") || strings.Contains(ipData.Country, "Switz") {
|
||||
color.Success.Println("SCHOKI")
|
||||
}
|
||||
|
||||
color.Notice.Println("どうぞ")
|
||||
}
|
||||
|
||||
func runCmd(retChan chan<- string, cmds string, args ...string) {
|
||||
cmd := exec.Command(cmds, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil && cmd.ProcessState.ExitCode() != 1 {
|
||||
retChan <- fmt.Sprintln(color.Error.Sprint(err))
|
||||
return
|
||||
}
|
||||
retChan <- string(out)
|
||||
}
|
||||
|
||||
func getIP(retChan chan<- string) {
|
||||
// get public IP
|
||||
req := fasthttp.AcquireRequest()
|
||||
resp := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseRequest(req)
|
||||
defer fasthttp.ReleaseResponse(resp)
|
||||
req.SetRequestURI("https://checkip.amazonaws.com/")
|
||||
err := fasthttp.Do(req, resp)
|
||||
if err != nil {
|
||||
retChan <- "ERR: " + fmt.Sprintln(err)
|
||||
return
|
||||
}
|
||||
if resp.StatusCode() != fasthttp.StatusOK {
|
||||
retChan <- fmt.Sprintf("ERR: Status code %d\n", resp.StatusCode())
|
||||
return
|
||||
}
|
||||
contType := resp.Header.Peek("Content-Type")
|
||||
if bytes.Index(contType, []byte("text/plain")) != 0 {
|
||||
retChan <- fmt.Sprintf("ERR: Unexpected content type %s\n", contType)
|
||||
return
|
||||
}
|
||||
contentEncoding := resp.Header.Peek("Content-Encoding")
|
||||
var body []byte
|
||||
if bytes.EqualFold(contentEncoding, []byte("gzip")) {
|
||||
body, _ = resp.BodyGunzip()
|
||||
} else {
|
||||
body = resp.Body()
|
||||
}
|
||||
retChan <- string(body)
|
||||
}
|
||||
|
||||
func getIPData(retChan chan<- string, retDataChan chan<- IPData) {
|
||||
req := fasthttp.AcquireRequest()
|
||||
resp := fasthttp.AcquireResponse()
|
||||
defer fasthttp.ReleaseRequest(req)
|
||||
defer fasthttp.ReleaseResponse(resp)
|
||||
req.SetRequestURI("https://ipleak.net/json/")
|
||||
err := fasthttp.Do(req, resp)
|
||||
if err != nil {
|
||||
retChan <- "ERR: " + fmt.Sprintln(err)
|
||||
return
|
||||
}
|
||||
if resp.StatusCode() != fasthttp.StatusOK {
|
||||
retChan <- fmt.Sprintf("ERR: Status code %d\n", resp.StatusCode())
|
||||
return
|
||||
}
|
||||
contType := resp.Header.Peek("Content-Type")
|
||||
if bytes.Index(contType, []byte("application/json")) != 0 {
|
||||
retChan <- fmt.Sprintf("ERR: Unexpected content type %s\n", contType)
|
||||
return
|
||||
}
|
||||
contentEncoding := resp.Header.Peek("Content-Encoding")
|
||||
var body []byte
|
||||
if bytes.EqualFold(contentEncoding, []byte("gzip")) {
|
||||
body, _ = resp.BodyGunzip()
|
||||
} else {
|
||||
body = resp.Body()
|
||||
}
|
||||
// color.Comment.Println(string(body))
|
||||
// parse
|
||||
parsed, err := fastjson.ParseBytes(body)
|
||||
if err != nil {
|
||||
retChan <- "ERR: " + fmt.Sprintln(err)
|
||||
return
|
||||
}
|
||||
readVal := parsed.Get("ip")
|
||||
if readVal == nil {
|
||||
retChan <- "ERR: Error while parsing JSON"
|
||||
return
|
||||
}
|
||||
ip, err := readVal.StringBytes()
|
||||
if err != nil {
|
||||
retChan <- "ERR: " + fmt.Sprintln(err)
|
||||
return
|
||||
}
|
||||
data := IPData{}
|
||||
data.IP = string(ip)
|
||||
if readVal = parsed.Get("country_code"); readVal != nil {
|
||||
data.CountryC = string(readVal.GetStringBytes())
|
||||
}
|
||||
if readVal = parsed.Get("country_name"); readVal != nil {
|
||||
data.Country = string(readVal.GetStringBytes())
|
||||
}
|
||||
if readVal = parsed.Get("region_code"); readVal != nil {
|
||||
data.RegionC = string(readVal.GetStringBytes())
|
||||
}
|
||||
if readVal = parsed.Get("region_name"); readVal != nil {
|
||||
data.Region = string(readVal.GetStringBytes())
|
||||
}
|
||||
if readVal = parsed.Get("continent_code"); readVal != nil {
|
||||
data.ContinentC = string(readVal.GetStringBytes())
|
||||
}
|
||||
if readVal = parsed.Get("continent_name"); readVal != nil {
|
||||
data.Continent = string(readVal.GetStringBytes())
|
||||
}
|
||||
if readVal = parsed.Get("city_name"); readVal != nil {
|
||||
data.City = string(readVal.GetStringBytes())
|
||||
}
|
||||
retChan <- fmt.Sprintln(data.IP)
|
||||
retDataChan <- data
|
||||
close(retDataChan)
|
||||
}
|
||||
Reference in New Issue
Block a user