Skip to content

Commit

Permalink
Merge pull request #435 from MortezaBashsiz/golang-v1.6-Xray-core
Browse files Browse the repository at this point in the history
Golang v1.6 xray core
  • Loading branch information
SonyaCore authored Apr 13, 2023
2 parents a03ac8b + 88ed541 commit 84bb412
Show file tree
Hide file tree
Showing 16 changed files with 775 additions and 132 deletions.
71 changes: 57 additions & 14 deletions golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,39 @@
![go]
![version]

### CFScanner is a tool written in Golang that scans Cloudflare's edge IPs and locates ones that are viable for use with V2Ray/Xray. It aims to identify edge IPs that are accessible and not blocked.
CFScanner is a powerful tool written in Golang specifically designed to scan Cloudflare's edge IPs and identify viable options for use with V2Ray/Xray.

### This program is similar to the bash version, utilizing v2ray+vmess+websocket+tls by default when the VPN flag is enabled. If you wish to use it behind your Cloudflare proxy, you will need to set up a vmess account. Otherwise, the program will use the default configuration.
Its main objective is to locate edge IPs that are accessible and not blocked. With its built-in xray-core, CFScanner leverages xray+vmess+websocket+tls by default when the VPN flag is enabled.

If you prefer to use it behind your Cloudflare proxy, you will need to set up a vmess account. However, if no specific configuration is provided, the program will automatically use the default settings.
# Requirements

- Golang v1.18 or higher
- Golang v1.20

# Installation

To install CFScanner, clone the repository and build the binary using the following commands:
### Getting the latest version from release page
Latest release version of golang CFScanner are available in [releases](https://github.com/MortezaBashsiz/CFScanner/releases)
section


### Build instructions

If you prefer to build CFScanner from source, you can follow these instructions:

Clone the repository by running the following command in your terminal:
```bash
git clone https://github.com/MortezaBashsiz/CFScanner.git
```
Navigate to the "golang" directory within the cloned repository:

```bash
cd CFScanner/golang
go build
```

Build the binary using the "go build" command with additional flags for trimming the path and setting linker flags for smaller binary size:
```bash
go build -o CFScanner -trimpath -ldflags "-s -w -buildid=" .
```

## Get Configuration file
Expand Down Expand Up @@ -57,7 +74,8 @@ CFScanner takes several arguments:
|------------------------|--------------------------------------------------------------------------------------------------|
| --threads -t | Number of threads to use for parallel scanning. Default is 1. |
| --config -c | The path to the config file. (Required) |
| --vpn | If passed, test with creating VPN connections. |
| --vpn | If passed, test with creating xray-core connections. |
| --loglevel -l | The log level for xray-core (default "none") |
| --subnets -s | The file or subnet. Each line should be in the form of ip.ip.ip.ip/subnet_mask or ip.ip.ip.ip. |
| --shuffle | Shuffling given subnet file or input |
| --upload | If passed, upload test will be conducted. |
Expand All @@ -70,17 +88,36 @@ CFScanner takes several arguments:
| --fronting-timeout | Maximum time to wait for fronting response. Default is 1.0. |
| --download-latency | Maximum allowed latency for download. Default is 2.0. |
| --upload-latency | Maximum allowed latency for upload. Default is 2.0. |
| --startprocess-timeout | Process timeout for v2ray. Default is 12. |
| --vpn-path | Custom V2Ray binary path for using v2ray binary in another directory. |
| --writer | Custom output writer for writing interim results. available writers : `csv`/`json` |
# KeyEvent Listeners
| --writer | Custom output writer for writing interim results. available writers : `csv`/`json` |

# Features

### KeyEvent Listeners
CFScanner supports pause and resume progress

- For Pausing current progress press `p`

- For Resuming current progress press `r`

### XRay Core
This Program has built-in Xray-core for testing connection with vpn

xray-core has 5 log levels

**Available log levels**
- debug
- info
- warning
- error
- none

default loglevel is none.

---

# Examples


### Load configuration file and load subnet file for scanning

```bash
Expand All @@ -105,21 +142,27 @@ CFScanner supports pause and resume progress
./CFScanner --config config.real --subnets 172.20.0.0/24 --threads 4 --tries 3
```

### Load configurations file with subnet file and using vpn mode with another v2ray binary
### Load configurations file with subnet file and using vpn mode

```bash
./CFScanner --config config.real --subnets 172.20.0.0/24 --vpn --vpn-path ~/v2ray-macos-arm64-v8a/v2ray
./CFScanner --config config.real --subnets 172.20.0.0/24 --vpn
```

---

## Output

Two files are stored for each (complete) run of the program

#### Writer Results
- Interim results file (e.g., `2023-03-10_20:49:30_result.csv` or `2023-03-10_20:49:30_result.json`)
- Includes the unsorted intermediate results in writer format. Useful in case the scanning process is not complete.
- Includes the unsorted intermediate results in specified writer format. Useful in case the scanning process is not complete.
#### Sorted Results
- Final results file (e.g., `2023-03-10_20:49:30_final.txt`)
- Includes the final sorted results. The results are sorted ascending ly based on the download latency time.

all results are stored in `result` folder

# License

CFScanner is released under the [GPL-3](../LICENSE) license.
Expand All @@ -129,4 +172,4 @@ CFScanner is released under the [GPL-3](../LICENSE) license.
Contributions are welcome! Please read [CONTRIBUTING.md](../CONTRIBUTING.md) for more information.

[go]: https://img.shields.io/badge/Go-cyan?logo=go
[version]: https://img.shields.io/badge/Version-1.4-blue
[version]: https://img.shields.io/badge/Version-1.6-blue
8 changes: 3 additions & 5 deletions golang/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ var nTries int

var configPath string
var subnets string
var vpnPath string

var Vpn bool
var Loglevel string
var doUploadTest bool
var fronting bool
var shuffle bool
Expand All @@ -19,7 +19,6 @@ var minULSpeed float64
var maxDLTime float64
var maxULTime float64

var startProcessTimeout float64
var frontingTimeout float64
var maxDLLatency float64
var maxULLatency float64
Expand All @@ -31,7 +30,8 @@ var writerType string
func RegisterCommands(rootCmd *cobra.Command) {
rootCmd.PersistentFlags().IntVarP(&threads, "threads", "t", 1, "Number of threads to use for parallel scanning")
rootCmd.PersistentFlags().StringVarP(&configPath, "config", "c", "", "The path to the config file")
rootCmd.PersistentFlags().BoolVar(&Vpn, "vpn", false, "If passed, test with creating vpn connections")
rootCmd.PersistentFlags().BoolVar(&Vpn, "vpn", false, "If passed, test with creating xray-core connections")
rootCmd.PersistentFlags().StringVarP(&Loglevel, "loglevel", "l", "none", "The log level for xray-core")
rootCmd.PersistentFlags().StringVarP(&subnets, "subnets", "s", "", "The file or subnet. each line should be in the form of ip.ip.ip.ip/subnet_mask or ip.ip.ip.ip.")
rootCmd.PersistentFlags().BoolVar(&shuffle, "shuffle", false, "Shuffling given subnet file or input")
rootCmd.PersistentFlags().BoolVar(&doUploadTest, "upload", false, "If passed, upload test will be conducted")
Expand All @@ -44,8 +44,6 @@ func RegisterCommands(rootCmd *cobra.Command) {
rootCmd.PersistentFlags().Float64Var(&frontingTimeout, "fronting-timeout", 1.0, "Maximum time to wait for fronting response")
rootCmd.PersistentFlags().Float64Var(&maxDLLatency, "download-latency", 3.0, "Maximum allowed latency for download")
rootCmd.PersistentFlags().Float64Var(&maxULLatency, "upload-latency", 3.0, "Maximum allowed latency for upload")
rootCmd.PersistentFlags().Float64Var(&startProcessTimeout, "startprocess-timeout", 12, "Process timeout for v2ray")
rootCmd.PersistentFlags().StringVar(&vpnPath, "vpn-path", "", "Custom V2Ray binary path for using v2ray binary in another directory")
rootCmd.PersistentFlags().StringVar(&writerType, "writer", "csv", "Custom output writer for writing interim results. [csv/json]")

}
7 changes: 3 additions & 4 deletions golang/configuration/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

var (
PROGRAMDIR = filepath.Dir(os.Args[0])
BIN = filepath.Join(PROGRAMDIR, "..", "bin", "v2ray")
DIR = filepath.Join(PROGRAMDIR, "config")
RESULTDIR = filepath.Join(PROGRAMDIR, "result")
StartDtStr = time.Now().Format("2006-01-02_15:04:05")
Expand All @@ -31,7 +30,6 @@ WS Header Host: %v%v%v
WS Header Path : %v%v%v
Address Port : %v%v%v
SNI : %v%v%v
Start Proccess Timeout : %v%v%v
Upload Test : %v%v%v
Fronting Request Test : %v%v%v
Minimum Download Speed : %v%v%v
Expand All @@ -42,7 +40,8 @@ Fronting Timeout : %v%v%v
Maximum Download Latency : %v%v%v
Maximum Upload Latency : %v%v%v
Number of Tries : %v%v%v
VPN Mode : %v%v%v
Xray-core : %v%v%v
Xray-loglevel : %v%v%v
Shuffling : %v%v%v
Writer : %v%v%v
Total Threads : %v%v%v
Expand All @@ -53,7 +52,6 @@ Total Threads : %v%v%v
utils.Colors.OKBLUE, C.Config.WsHeaderPath, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Config.AddressPort, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Config.Sni, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Worker.StartProcessTimeout, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Config.DoUploadTest, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Config.DoFrontingTest, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Worker.Download.MinDlSpeed, utils.Colors.ENDC,
Expand All @@ -65,6 +63,7 @@ Total Threads : %v%v%v
utils.Colors.OKBLUE, C.Worker.Upload.MaxUlLatency, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Config.NTries, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Worker.Vpn, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.LogLevel, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Shuffling, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Config.Writer, utils.Colors.ENDC,
utils.Colors.OKBLUE, C.Worker.Threads, utils.Colors.ENDC,
Expand Down
10 changes: 5 additions & 5 deletions golang/configuration/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ type Configuration struct {
Config ConfigStruct
Worker Worker
Shuffling bool
LogLevel string
}

type Worker struct {
Download Download
Upload Upload
StartProcessTimeout float64 // seconds
Threads int
Vpn bool
Download Download
Upload Upload
Threads int
Vpn bool
}

type ConfigStruct struct {
Expand Down
47 changes: 45 additions & 2 deletions golang/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,57 @@
module CFScanner

go 1.18
go 1.20

require (
github.com/eiannone/keyboard v0.0.0-20220611211555-0d226195f203
github.com/spf13/cobra v1.6.1
github.com/xtls/xray-core v1.8.0
)

require (
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/dgryski/go-metro v0.0.0-20211217172704-adc40b04c140 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/ghodss/yaml v1.0.1-0.20220118164431-d8423dcdf344 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/klauspost/cpuid/v2 v2.2.4 // indirect
github.com/miekg/dns v1.1.51 // indirect
github.com/onsi/ginkgo/v2 v2.9.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pires/go-proxyproto v0.6.2 // indirect
github.com/quic-go/qtls-go1-19 v0.2.1 // indirect
github.com/quic-go/qtls-go1-20 v0.1.1 // indirect
github.com/quic-go/quic-go v0.33.0 // indirect
github.com/refraction-networking/utls v1.2.3-0.20230308205431-4f1df6c200db // indirect
github.com/riobard/go-bloom v0.0.0-20200614022211-cdc8013cb5b3 // indirect
github.com/sagernet/sing v0.1.7 // indirect
github.com/sagernet/sing-shadowsocks v0.1.1 // indirect
github.com/sagernet/wireguard-go v0.0.0-20221116151939-c99467f53f2c // indirect
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
github.com/v2fly/ss-bloomring v0.0.0-20210312155135-28617310f63e // indirect
github.com/xtls/reality v0.0.0-20230309125256-0d0713b108c8 // indirect
go.starlark.net v0.0.0-20230302034142-4b1e35fe2254 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/exp v0.0.0-20230307190834-24139beb5833 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect
google.golang.org/grpc v1.53.0 // indirect
google.golang.org/protobuf v1.29.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gvisor.dev/gvisor v0.0.0-20220901235040-6ca97ef2ce1c // indirect
lukechampine.com/blake3 v1.1.7 // indirect
)
Loading

0 comments on commit 84bb412

Please sign in to comment.