Skip to content

Commit

Permalink
Merge pull request #11 from Kuucheen/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Kuucheen committed Jan 27, 2024
2 parents 9f6c067 + a962c21 commit 6d15042
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 36 deletions.
7 changes: 5 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

set OUTPUT_FOLDER=bin
set BINARY_NAME=KC-Checker
set VERSION=1.0.4
set DESCRIPTION=Open source proxy checker built in Go, fast and beautiful. Created by Kuchen (Kuucheen on GitHub).

echo Compiling for Windows...
set GOOS=windows
set GOARCH=amd64
go build -o %OUTPUT_FOLDER%\%BINARY_NAME%.exe
go build -ldflags="-X 'main.Version=%VERSION%' -X 'main.Description=%DESCRIPTION%'" -o %OUTPUT_FOLDER%\%BINARY_NAME%.exe

if %ERRORLEVEL% neq 0 (
echo Compilation failed for Windows
exit /b %ERRORLEVEL%
Expand All @@ -16,7 +19,7 @@ echo Compilation for Windows successful
echo Compiling for Linux...
set GOOS=linux
set GOARCH=amd64
go build -o %OUTPUT_FOLDER%\%BINARY_NAME%
go build -ldflags="-X 'main.Version=%VERSION%' -X 'main.Description=%DESCRIPTION%'" -o %OUTPUT_FOLDER%\%BINARY_NAME%
if %ERRORLEVEL% neq 0 (
echo Compilation failed for Linux
exit /b %ERRORLEVEL%
Expand Down
17 changes: 3 additions & 14 deletions charm/drawLogo.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,14 @@ func DrawLogo() {
}
}

// A logoModel can be more or less any type of data. It holds all the data for a
// program, so often it's a struct. For this simple example, however, all
// we'll need is a simple integer.
type logoModel int

var times int

// Init optionally returns an initial command we should run. In this case we
// want to start the timer.
func (m logoModel) Init() tea.Cmd {
return tea.Batch(tick, tea.ClearScreen)
}

// Update is called when messages are received. The idea is that you inspect the
// message and send back an updated logoModel accordingly. You can also return
// a command, which is a function that performs I/O and returns a message.
func (m logoModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
Expand All @@ -51,17 +43,16 @@ func (m logoModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, nil
}

// View returns a string based on data in the logoModel. That string which will be
// rendered to the terminal.
func (m logoModel) View() string {
logo := " _ ______ ____ _ _ \n | |/ / ___| / ___| |__ ___ ___| | _____ _ __ \n | ' / | | | | '_ \\ / _ \\/ __| |/ / _ \\ '__|\n | . \\ |___ | |___| | | | __/ (__| < __/ | \n |_|\\_\\____| \\____|_| |_|\\___|\\___|_|\\_\\___|_| \n \n\nby github.com/Kuucheen"
logo := " _ _ _______ _______ _ _ \n(_) | (_______) (_______) | | | \n _____| |_ _ | |__ _____ ____| | _ _____ ____ \n | _ _) | | | | _ \\| ___ |/ ___) |_/ ) ___ |/ ___)\n| | \\ \\| |_____ | |_____| | | | ____( (___| _ (| ____| |\n|_| \\_)\\______) \\______)_| |_|_____)\\____)_| \\_)_____)_|\n\n"
logo += "by github.com/Kuucheen"

width := threadPhase.GetWidth()

var style = lipgloss.NewStyle().
Width(width).
Align(lipgloss.Center).
Foreground(lipgloss.Color("#8271BB")).
Foreground(lipgloss.Color("#6C44BB")).
SetString(logo)

var linestyle = style.Copy().
Expand All @@ -74,8 +65,6 @@ func (m logoModel) View() string {
return str
}

// Messages are events that we respond to in our Update function. This
// particular one indicates that the timer has ticked.
type tickMsg time.Time

func tick() tea.Msg {
Expand Down
1 change: 1 addition & 0 deletions charm/hostRunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ func RunHostsDisplay() {
go helper.Dispatcher(helper.GetCleanedProxies())
}

threadPhase.SetTime()
threadPhase.RunBars()
}
6 changes: 4 additions & 2 deletions charm/threadPhase/displayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (m model) Init() tea.Cmd {
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
if helper.HasFinished {
threadPhase = false
SetStopTime()
}
switch msg := msg.(type) {
case tea.KeyMsg:
Expand Down Expand Up @@ -197,8 +198,9 @@ func (m model) View() string {

return lipgloss.JoinHorizontal(lipgloss.Top, bars.String(),
lipgloss.JoinVertical(lipgloss.Center,
lipgloss.JoinVertical(lipgloss.Left, lipgloss.JoinVertical(lipgloss.Left, lipgloss.JoinHorizontal(lipgloss.Top, getStyledQueue(),
getStyledInfo(eliteCount, anonymousCount, transparentCount)),
lipgloss.JoinVertical(lipgloss.Left, lipgloss.JoinVertical(lipgloss.Left,
lipgloss.JoinHorizontal(lipgloss.Top, getStyledQueue(),
getStyledInfo(eliteCount, anonymousCount, transparentCount)),
percentageBar.String()), extraString), greenStyle(outputPath)),
)
}
Expand Down
72 changes: 64 additions & 8 deletions charm/threadPhase/styler.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package threadPhase

import (
"KC-Checker/common"
"KC-Checker/helper"
"fmt"
"github.com/charmbracelet/lipgloss"
"golang.org/x/crypto/ssh/terminal"
"math"
"os"
"strconv"
"strings"
"time"
)

var (
startTime = time.Now()
stopTime = time.Now()
stoppedTime = false
typeStyle = lipgloss.NewStyle().Italic(true)
eliteStyle = typeStyle.Copy().Foreground(lipgloss.Color("#624CAB"))
anonymousStyle = typeStyle.Copy().Foreground(lipgloss.Color("#57CC99"))
Expand All @@ -35,31 +41,58 @@ func getStyledQueue() string {
addString += transparentStyle.Render("T")
}

times := strings.Repeat(" ", 21-len(value.Full))
ip := value.Full

retString += fmt.Sprintf("[%s]%s %s\n", addString, times, value.Full)
}
if len(retString) >= 2 {
retString = retString[:len(retString)-1]
if common.GetPrivacyMode() {
ip = getPrivateFull(value)
}

times := strings.Repeat(" ", int(math.Abs(float64(21-len(ip)))))

retString += fmt.Sprintf("[%s]%s %s\n", addString, times, ip)
}

retString += strings.Repeat("─", GetWidth()/4) + "\n" +
getFormattedInfo("CPM:", int(helper.GetCPM()))

return lipgloss.NewStyle().BorderStyle(lipgloss.NormalBorder()).
BorderBottom(true).
BorderRight(true).
Align(lipgloss.Center).
Height(5).
Height(7).
Width(GetWidth() / 4).
Render(retString)
}

func getPrivateFull(proxy *helper.Proxy) string {
splitted := strings.Split(proxy.Ip, ".")
return splitted[0] + "." +
strings.Repeat("*", len(splitted[1])) + "." +
strings.Repeat("*", len(splitted[2])) + "." +
strings.Repeat("*", len(splitted[3])) + ":" +
strings.Repeat("*", 5)
}

func getStyledInfo(elite int, anon int, trans int) string {
activeThreads := helper.GetActive()

timeCalc := time.Now()

if stoppedTime {
timeCalc = stopTime
}

timeSince := timeCalc.Sub(startTime)

ms := fmt.Sprintf("%02d", int(timeSince.Milliseconds()%1000/10))

retString := getFormattedInfo("Threads:", activeThreads) + "\n" +
getFormattedInfo("Elite:", elite) + "\n" +
getFormattedInfo("Anonymous:", anon) + "\n" +
getFormattedInfo("Transparent:", trans) + "\n" +
getFormattedInfo("Invalid:", helper.GetInvalid())
getFormattedInfo("Invalid:", helper.GetInvalid()) + "\n" +
strings.Repeat("─", GetWidth()/4-6) + "\n" +
getFormattedInfoStr("Time:", strconv.Itoa(int(timeSince.Seconds()))+"."+ms+"s")

return lipgloss.NewStyle().
BorderStyle(lipgloss.NormalBorder()).
Expand All @@ -76,6 +109,29 @@ func GetWidth() int {
}

func getFormattedInfo(str string, num int) string {
MAXLENGTH := 18

numStr := strconv.Itoa(num)
return str + strings.Repeat(" ", 18-len(str)-len(numStr)) + numStr
length := len(str) + len(numStr)

if length > MAXLENGTH {
length = MAXLENGTH
}

return str + strings.Repeat(" ", MAXLENGTH-length) + numStr
}

func getFormattedInfoStr(str string, value string) string {
return str + strings.Repeat(" ", 18-len(str)-len(value)) + value
}

func SetTime() {
startTime = time.Now()
}

func SetStopTime() {
if !stoppedTime {
stopTime = time.Now()
stoppedTime = true
}
}
3 changes: 3 additions & 0 deletions common/Setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Config struct {
Threads int `json:"threads"`
Retries int `json:"retries"`
Timeout int `json:"timeout"`
PrivacyMode bool `json:"privacy_mode"`
IpLookup string `json:"iplookup"`
Judges []string `json:"judges"`
Blacklisted []string `json:"blacklisted"`
Expand Down Expand Up @@ -38,6 +39,8 @@ func GetConfig() Config {
return config
}

func GetPrivacyMode() bool { return config.PrivacyMode }

func DoBanCheck() bool {
return config.Bancheck != ""
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE8y6bre4H8=
github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
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.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
Expand Down Expand Up @@ -47,6 +52,7 @@ golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
Expand Down
8 changes: 5 additions & 3 deletions helper/CheckerHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func Request(proxy *Proxy) (string, int) {
return RequestCustom(proxy, common.FastestJudge)
}

// RequestCustom makes a request to the provided siteUrl with the provided proxy
func RequestCustom(proxy *Proxy, siteUrl string) (string, int) {
//Errors would destroy the whole display while checking
log.SetOutput(io.Discard)

proxyURL, err := url.Parse(GetTypeName() + "://" + proxy.Full)
Expand All @@ -49,16 +51,17 @@ func RequestCustom(proxy *Proxy, siteUrl string) (string, int) {

switch GetTypeName() {
case "http":
transport = &http.Transport{Proxy: http.ProxyURL(proxyURL)}
transport = &http.Transport{Proxy: http.ProxyURL(proxyURL), DisableKeepAlives: true}
case "socks4", "socks5":
//udp doesn't work for some reason
dialer, err := proxy2.SOCKS5("tcp", proxy.Full, nil, proxy2.Direct)
if err != nil {
return "Error creating SOCKS dialer", -1
}
transport = &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
},
}, DisableKeepAlives: true,
}
}

Expand Down Expand Up @@ -96,5 +99,4 @@ func RequestCustom(proxy *Proxy, siteUrl string) (string, int) {
}

return string(resBody), status

}
12 changes: 6 additions & 6 deletions helper/ProxyHelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
)

type Proxy struct {
ip string
port int
Ip string
Port int
Full string
Level int
checks int
Expand All @@ -35,12 +35,12 @@ func ToProxies(arr []string) []*Proxy {
dat, err := strconv.Atoi(temp[1])

if err != nil {
fmt.Print("Not a valid port: ", err)
fmt.Print("Not a valid Port: ", err)
}

newArr = append(newArr, &Proxy{
ip: temp[0],
port: dat,
Ip: temp[0],
Port: dat,
Full: temp[0] + ":" + temp[1],
})
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func GetCleanedProxies() []*Proxy {
var cleaned []*Proxy

for _, value := range normal {
if !hasString(forbidden, value.ip) {
if !hasString(forbidden, value.Ip) {
cleaned = append(cleaned, value)
}
}
Expand Down

0 comments on commit 6d15042

Please sign in to comment.