Skip to content

Commit

Permalink
Adding project files
Browse files Browse the repository at this point in the history
  • Loading branch information
ysdragon authored May 14, 2023
1 parent fed7667 commit 7a09dd5
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SERVER_IP=127.0.0.1
SERVER_PORT=12203
RCON_PASSWORD=123123
WAIT_INTERVAL=10
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module antivpn

go 1.20

require (
github.com/fatih/color v1.15.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
golang.org/x/sys v0.6.0 // indirect
)
12 changes: 12 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
135 changes: 135 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package main

import (
"os"
"fmt"
"strconv"
"io/ioutil"
"net"
"net/http"
"regexp"
"strings"
"time"

"github.com/joho/godotenv"
"github.com/fatih/color"
)

func main() {

err := godotenv.Load("config.ini")
if err != nil {
color.Red("Error loading config.ini file")
fmt.Println()
return
}

serverIp := os.Getenv("SERVER_IP")
serverPortStr := os.Getenv("SERVER_PORT")
serverPort, err := strconv.Atoi(serverPortStr)
if err != nil {
color.Red("Invalid server port")
fmt.Println()
return
}

rconPassword := os.Getenv("RCON_PASSWORD")
waitInterval := os.Getenv("WAIT_INTERVAL")
waitDuration, err := time.ParseDuration(waitInterval + "s")
if err != nil {
color.Red("Invalid wait interval")
fmt.Println()
return
}


year := color.YellowString(fmt.Sprintf("%d", time.Now().Year()))
fmt.Printf("\n%s - %s\n\n", color.RedString("- ANTI VPN BY DraGoN"), year)

for {
query := "\xFF\xFF\xFF\xFF\x02rcon " + rconPassword + " status \n"

socket, err := net.Dial("udp", fmt.Sprintf("%s:%d", serverIp, serverPort))
if err != nil {
color.Red("Error connecting to server! Retrying in " + waitDuration.String() + " seconds...")
fmt.Println()
time.Sleep(waitDuration)
continue
}

socket.Write([]byte(query))

socket.SetReadDeadline(time.Now().Add(3 * time.Second))
data := make([]byte, 1500)
_, err = socket.Read(data)

if err != nil {
color.Red("Server is offline! Retrying in " + waitDuration.String() + " seconds...")
fmt.Println()
time.Sleep(waitDuration)
continue
}

dataReturned := string(data)
regexIpAddress := regexp.MustCompile(`\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(?:\/\d{2})?`)
ipAddresses := regexIpAddress.FindAllString(dataReturned, -1)

socket.Close()

for _, ipAddress := range ipAddresses {
fmt.Printf("%s ", color.GreenString(ipAddress))
fmt.Printf("- %s: ", color.MagentaString("Using VPN/Proxy"))
detectVPN(ipAddress, serverIp, serverPort, rconPassword)
}

if len(ipAddresses) == 0 {
color.Red("- No Players!")
fmt.Println()
}

time.Sleep(waitDuration)
}
}

func detectVPN(ipAddress string, serverIp string, serverPort int, rconPassword string) {
client := &http.Client{}
url := fmt.Sprintf("https://blackbox.ipinfo.app/lookup/%s", ipAddress)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36")
resp, err := client.Do(req)

if err != nil {
color.Red("Could not get VPN information.")
fmt.Println()
return
}

defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)

if strings.TrimSpace(string(body)) == "Y" {
color.Yellow("YES!!")
fmt.Println()

socket, _ := net.Dial("udp", fmt.Sprintf("%s:%d", serverIp, serverPort))
banCommand := fmt.Sprintf("\xFF\xFF\xFF\xFF\x02rcon %s banipr %s Using VPN\n", rconPassword, ipAddress)
socket.Write([]byte(banCommand))

socket.SetReadDeadline(time.Now().Add(3 * time.Second))
data := make([]byte, 2048)
_, err := socket.Read(data)

if err != nil {
fmt.Println(err)
return
}

response := string(data)
response = strings.Replace(response, "....print\n", "", -1)
fmt.Println(response)
socket.Close()
} else if strings.TrimSpace(string(body)) == "N" {
color.Red("No")
fmt.Println()
}
}

0 comments on commit 7a09dd5

Please sign in to comment.