├── .gitignore ├── rustfmt.toml ├── src ├── i18n │ ├── mod.rs │ ├── interface.rs │ ├── zh_cn.rs │ └── en_us.rs ├── data │ ├── mod.rs │ └── ips.rs ├── controller │ ├── mod.rs │ ├── real_delay_controller.rs │ ├── download_controller.rs │ └── ping_controller.rs ├── utils │ ├── mod.rs │ ├── args.rs │ ├── ping.rs │ ├── bulk_ping.rs │ ├── download.rs │ ├── real_delay.rs │ ├── ipv6_range.rs │ └── get_all_ips.rs └── main.rs ├── Cargo.toml ├── .github └── workflows │ ├── build-arm.yml │ └── build.yml ├── README.md ├── README-en_US.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | tab_spaces = 2 -------------------------------------------------------------------------------- /src/i18n/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod en_us; 2 | pub mod interface; 3 | pub mod zh_cn; 4 | -------------------------------------------------------------------------------- /src/data/mod.rs: -------------------------------------------------------------------------------- 1 | mod ips; 2 | pub use ips::IPV4_IPS_ORIGINAL; 3 | pub use ips::IPV4_IPS_TESTED; 4 | pub use ips::IPV6_IPS; 5 | -------------------------------------------------------------------------------- /src/controller/mod.rs: -------------------------------------------------------------------------------- 1 | mod ping_controller; 2 | pub use ping_controller::ping_controller; 3 | 4 | mod download_controller; 5 | pub use download_controller::download_controller; 6 | 7 | mod real_delay_controller; 8 | pub use real_delay_controller::real_delay_controller; 9 | -------------------------------------------------------------------------------- /src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | mod download; 2 | pub use download::download; 3 | 4 | mod ping; 5 | pub use ping::ping; 6 | 7 | mod bulk_ping; 8 | pub use bulk_ping::bulk_ping; 9 | 10 | mod real_delay; 11 | pub use real_delay::bulk_real_delay; 12 | pub use real_delay::RealDelayRes; 13 | 14 | mod args; 15 | pub use args::get_args; 16 | 17 | mod get_all_ips; 18 | pub use get_all_ips::get_all_ips_v4; 19 | pub use get_all_ips::get_all_ips_v6; 20 | 21 | mod ipv6_range; 22 | pub use ipv6_range::IPv6Range; 23 | -------------------------------------------------------------------------------- /src/utils/args.rs: -------------------------------------------------------------------------------- 1 | use clap::Parser; 2 | 3 | /// 运行参数 4 | #[derive(Parser, Debug)] 5 | #[clap(name = "Cloudflare Speed Test")] 6 | #[clap( 7 | about = "---------------------\nCloudflare Speed Test\n---------------------\n\nTest ping, real delay and download speed of Cloudflare CDN Nodes to get the fastest IP (IPv4), without accessing any third-party servers." 8 | )] 9 | #[clap(version, author = "lixiang810")] 10 | pub struct Args { 11 | /// Custom IP file route 12 | #[clap(long, short)] 13 | pub custom_ip_file: Option, 14 | } 15 | 16 | pub fn get_args() -> Args { 17 | return Args::parse(); 18 | } 19 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cfst" 3 | version = "2.2.2" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | reqwest = { version = "0.11", features = ["json"] } 10 | tokio = { version = "1.20.1", features = ["rt", "rt-multi-thread", "macros"] } 11 | surge-ping = "0.7.0" 12 | iprange = "0.6.7" 13 | ipnet = "2.4.0" 14 | futures = "0.3.21" 15 | random-number = "0.1.7" 16 | indicatif = "0.16.2" 17 | relative-path = "1.7.0" 18 | dialoguer = "0.10.0" 19 | clap = { version = "3.1.6", features = ["derive"] } 20 | rand = { version = "0.8.5", features = ["small_rng"] } 21 | async-recursion = "1.0.0" 22 | -------------------------------------------------------------------------------- /.github/workflows/build-arm.yml: -------------------------------------------------------------------------------- 1 | name: Build ARM 2 | 3 | on: 4 | release: 5 | types: [created] 6 | workflow_dispatch: 7 | 8 | jobs: 9 | release-arm: 10 | name: release ${{ matrix.target }} 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@master 14 | - name: Compile and release 15 | uses: uraimo/run-on-arch-action@v2.3.0 16 | with: 17 | arch: aarch64 18 | distro: ubuntu20.04 19 | githubToken: ${{ secrets.GITHUB_TOKEN }} 20 | install: | 21 | apt-get update && apt-get upgrade -y && apt-get install curl -y 22 | curl https://sh.rustup.rs -sSf | sh -s -- -y 23 | run: | 24 | source "$HOME/.cargo/env" 25 | cargo build --release 26 | ls -la target/release 27 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | on: 2 | release: 3 | types: [created] 4 | 5 | jobs: 6 | release: 7 | name: release ${{ matrix.target }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | include: 13 | - target: x86_64-pc-windows-gnu 14 | archive: zip 15 | - target: x86_64-unknown-linux-musl 16 | archive: tar.gz tar.xz 17 | - target: x86_64-apple-darwin 18 | archive: zip 19 | steps: 20 | - uses: actions/checkout@master 21 | - name: Compile and release 22 | uses: rust-build/rust-build.action@latest 23 | env: 24 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 25 | RUSTTARGET: ${{ matrix.target }} 26 | ARCHIVE_TYPES: ${{ matrix.archive }} 27 | MINIFY: true 28 | -------------------------------------------------------------------------------- /src/utils/ping.rs: -------------------------------------------------------------------------------- 1 | use std::net::IpAddr; 2 | use std::time::Duration; 3 | use surge_ping::{IcmpPacket, PingSequence, Pinger}; 4 | use tokio::time; 5 | 6 | /// ## ping 7 | /// Ping 一个 IP 8 | pub async fn ping( 9 | ip: IpAddr, 10 | mut pinger: Pinger, 11 | ) -> Result<(IpAddr, Duration), Box> { 12 | const PAYLOAD: [u8; 64] = [255; 64]; 13 | let timeout = Duration::from_secs(2); 14 | pinger.timeout(timeout); 15 | let mut avg_time = Duration::from_secs(0); 16 | let mut interval = time::interval(Duration::from_secs(1)); 17 | for idx in 0..5 { 18 | interval.tick().await; 19 | match pinger.ping(PingSequence(idx), &PAYLOAD).await { 20 | Ok((IcmpPacket::V4(_packet), dur)) => { 21 | avg_time += dur; 22 | } 23 | Ok((IcmpPacket::V6(_packet), dur)) => { 24 | avg_time += dur; 25 | } 26 | Err(_) => { 27 | avg_time += timeout; 28 | } 29 | }; 30 | } 31 | // println!("[+] {} done.", pinger.destination); 32 | Ok((ip, avg_time / 5)) 33 | } 34 | -------------------------------------------------------------------------------- /src/utils/bulk_ping.rs: -------------------------------------------------------------------------------- 1 | use crate::utils::ping; 2 | use futures::future::join_all; 3 | use random_number::random; 4 | use std::net::IpAddr::{V4, V6}; 5 | use surge_ping::{Client, Config, PingIdentifier, ICMP}; 6 | 7 | /// ## bulk_ping 8 | /// 批量 Ping 9 | pub async fn bulk_ping<'a>( 10 | ips: Vec, 11 | ) -> Result, Box> { 12 | let client = match ips.get(0) { 13 | Some(V4(_)) => Client::new(&Config::default()).unwrap(), 14 | Some(V6(_)) => Client::new(&Config::builder().kind(ICMP::V6).build()).unwrap(), 15 | None => Client::new(&Config::default()).unwrap(), 16 | }; 17 | let mut tasks = vec![]; 18 | for ip in ips { 19 | let rand_num: u16 = random!(); 20 | let pinger = client.pinger(ip, PingIdentifier(rand_num)).await; 21 | tasks.push(tokio::spawn(ping(ip, pinger))); 22 | } 23 | let task_results = join_all(tasks).await; 24 | let mut result = Vec::new(); 25 | for task_result in task_results { 26 | let task_result_unwrapped = task_result.unwrap().unwrap(); 27 | if task_result_unwrapped.1 != std::time::Duration::from_secs(2) { 28 | result.push(task_result_unwrapped); 29 | } 30 | } 31 | Ok(result) 32 | } 33 | -------------------------------------------------------------------------------- /src/controller/real_delay_controller.rs: -------------------------------------------------------------------------------- 1 | use crate::i18n::interface::I18nItems; 2 | use crate::utils::bulk_real_delay; 3 | use crate::utils::RealDelayRes; 4 | use indicatif::ProgressBar; 5 | use std::error::Error; 6 | use std::net::IpAddr; 7 | use std::time::Duration; 8 | 9 | pub async fn real_delay_controller( 10 | ips: Vec<(IpAddr, Duration)>, 11 | i18n: &I18nItems<'_>, 12 | ) -> Result, Box> { 13 | let pb = ProgressBar::new(50); 14 | pb.tick(); 15 | pb.println(format!("{}", i18n.real_delay_controller_i18n)); 16 | let mut res_vec = Vec::new(); 17 | let mut i_temp = 0; 18 | while res_vec.len() < 50 && res_vec.len() != ips.len() { 19 | let mut bulk_vec = Vec::new(); 20 | for i in i_temp..i_temp + 10 { 21 | if i < ips.len() { 22 | bulk_vec.push(ips[i]); 23 | } 24 | } 25 | let res = bulk_real_delay(bulk_vec).await?; 26 | res.iter().for_each(|item| { 27 | if res_vec.len() < 50 { 28 | pb.inc(1); 29 | res_vec.push(*item); 30 | } 31 | }); 32 | i_temp += 10; 33 | } 34 | res_vec.sort_by(|a, b| a.real_delay.cmp(&b.real_delay)); 35 | pb.finish(); 36 | res_vec.truncate(10); 37 | Ok(res_vec) 38 | } 39 | -------------------------------------------------------------------------------- /src/utils/download.rs: -------------------------------------------------------------------------------- 1 | use reqwest::Url; 2 | use std::net::{IpAddr, SocketAddr}; 3 | 4 | /// ## Download 5 | /// 测试下载速度,返回值为 `Byte/s` 6 | pub async fn download(ip: IpAddr) -> Result> { 7 | let url_string = format!( 8 | "https://speed.cloudflare.com/__down?bytes={}", 9 | 1024 * 1024 * 1024 10 | ); 11 | let url = Url::parse(url_string.as_str())?; 12 | let client_builder = reqwest::ClientBuilder::new() 13 | .resolve("speed.cloudflare.com", SocketAddr::new(ip, 443)) 14 | .no_proxy(); 15 | let client = client_builder.build().unwrap(); 16 | let req = client.get(url).build().unwrap(); 17 | let mut resp_raw = match client.execute(req).await { 18 | Ok(t) => t, 19 | Err(_) => return Ok(0f64), 20 | }; 21 | let mut data_len: usize = 0; 22 | let now = std::time::Instant::now(); 23 | loop { 24 | let chunk_result = resp_raw.chunk().await; 25 | match chunk_result { 26 | Ok(Some(chunk)) => { 27 | if now.elapsed().as_secs() <= 5 { 28 | data_len += chunk.len(); 29 | } else { 30 | data_len += chunk.len(); 31 | break; 32 | } 33 | } 34 | Ok(None) => break, 35 | Err(_) => return Ok(0f64), 36 | } 37 | } 38 | Ok(data_len as f64 / now.elapsed().as_secs_f64()) 39 | } 40 | -------------------------------------------------------------------------------- /src/controller/download_controller.rs: -------------------------------------------------------------------------------- 1 | use crate::i18n::interface::I18nItems; 2 | use crate::utils::download; 3 | use crate::utils::RealDelayRes; 4 | use indicatif::ProgressBar; 5 | use std::error::Error; 6 | use std::net::IpAddr; 7 | use std::time::Duration; 8 | 9 | /// 下载测速返回值 10 | pub struct DownloadRes { 11 | pub ip: IpAddr, 12 | pub ping: Duration, 13 | pub real_delay: Duration, 14 | pub speed: f64, 15 | } 16 | 17 | /// ## download_controller 18 | /// 下载测速 19 | pub async fn download_controller( 20 | ips: Vec, 21 | i18n: &I18nItems<'_>, 22 | ) -> Result, Box> { 23 | let pb = ProgressBar::new(ips.len().try_into().unwrap()); 24 | pb.tick(); 25 | pb.println(format!( 26 | "{} {} {}", 27 | i18n.download_controller_i18n.total_before_num, 28 | ips.len(), 29 | i18n.download_controller_i18n.total_after_num, 30 | )); 31 | let mut result_vec = Vec::new(); 32 | for ip in ips { 33 | pb.println(format!( 34 | "{}{}", 35 | i18n.download_controller_i18n.testing, ip.ip 36 | )); 37 | let res = download(ip.ip).await?; 38 | result_vec.push(DownloadRes { 39 | ip: ip.ip, 40 | ping: ip.ping, 41 | real_delay: ip.real_delay, 42 | speed: res, 43 | }); 44 | pb.inc(1); 45 | } 46 | pb.finish(); 47 | result_vec.sort_by(|b, a| a.speed.partial_cmp(&b.speed).unwrap()); 48 | Ok(result_vec) 49 | } 50 | -------------------------------------------------------------------------------- /src/i18n/interface.rs: -------------------------------------------------------------------------------- 1 | pub struct DownloadControllerI18n<'a> { 2 | pub total_before_num: &'a str, 3 | pub total_after_num: &'a str, 4 | pub testing: &'a str, 5 | } 6 | 7 | pub struct ChooseIPsI18n<'a> { 8 | pub use_original_ips: &'a str, 9 | pub use_tested_ips: &'a str, 10 | pub use_online_ips: &'a str, 11 | } 12 | 13 | pub struct PingControllerI18n<'a> { 14 | pub reading_custom_file: &'a str, 15 | pub reading_custom_file_error: &'a str, 16 | pub getting_ips_from_cloudflare: &'a str, 17 | pub getting_ips_from_cloudflare_success: &'a str, 18 | pub getting_ips_from_cloudflare_failed: &'a str, 19 | pub internal_or_online: &'a str, 20 | pub choose_ips: &'a str, 21 | pub generating_ips: &'a str, 22 | pub prompt_part1: &'a str, 23 | pub prompt_part2: &'a str, 24 | pub prompt_part3: &'a str, 25 | pub invalid_input: &'a str, 26 | pub will_test_before_num: &'a str, 27 | pub will_test_after_num: &'a str, 28 | } 29 | 30 | pub struct MainI18n<'a> { 31 | pub test_result: &'a str, 32 | pub ip: &'a str, 33 | pub ping: &'a str, 34 | pub real_delay: &'a str, 35 | pub download_speed: &'a str, 36 | pub if_save_result: &'a str, 37 | pub result_saved: &'a str, 38 | pub cannot_get_dir: &'a str, 39 | pub failed_to_write: &'a str, 40 | } 41 | 42 | pub struct I18nItems<'a> { 43 | pub download_controller_i18n: DownloadControllerI18n<'a>, 44 | pub ping_controller_i18n: PingControllerI18n<'a>, 45 | pub real_delay_controller_i18n: &'a str, 46 | pub main_i18n: MainI18n<'a>, 47 | pub choose_ips_i18n: ChooseIPsI18n<'a>, 48 | } 49 | -------------------------------------------------------------------------------- /src/utils/real_delay.rs: -------------------------------------------------------------------------------- 1 | use futures::future::join_all; 2 | use reqwest::ClientBuilder; 3 | use std::net::{IpAddr, SocketAddr}; 4 | use std::time::{Duration, Instant}; 5 | 6 | /// 真实延迟测试返回值 7 | #[derive(Copy, Clone)] 8 | pub struct RealDelayRes { 9 | pub ip: IpAddr, 10 | pub ping: Duration, 11 | pub real_delay: Duration, 12 | } 13 | 14 | /// ## bulk_real_delay 15 | /// 批量测试真实延迟 16 | pub async fn bulk_real_delay( 17 | ips: Vec<(IpAddr, Duration)>, 18 | ) -> Result, Box> { 19 | let mut tasks = Vec::new(); 20 | for ip in ips { 21 | tasks.push(tokio::spawn(real_delay(ip))); 22 | } 23 | let task_results = join_all(tasks).await; 24 | let mut result = Vec::new(); 25 | for task_result in task_results { 26 | let task_result_unwrapped = task_result.unwrap(); 27 | match task_result_unwrapped { 28 | Ok(res) => result.push(RealDelayRes { 29 | ip: res.0, 30 | ping: res.1, 31 | real_delay: res.2, 32 | }), 33 | Err(_) => {} 34 | } 35 | } 36 | Ok(result) 37 | } 38 | 39 | /// ## real_delay 40 | /// 测试真实延迟 41 | async fn real_delay( 42 | ip: (IpAddr, Duration), 43 | ) -> Result<(IpAddr, Duration, Duration), Box> { 44 | let client = ClientBuilder::new() 45 | .resolve("www.cloudflare.com", SocketAddr::new(ip.0, 443)) 46 | .no_proxy() 47 | .timeout(Duration::from_secs(2)) 48 | .build() 49 | .unwrap(); 50 | let dur = Instant::now(); 51 | client.get("https://www.cloudflare.com").send().await?; 52 | return Ok((ip.0, ip.1, dur.elapsed())); 53 | } 54 | -------------------------------------------------------------------------------- /src/controller/ping_controller.rs: -------------------------------------------------------------------------------- 1 | use crate::i18n::interface::I18nItems; 2 | use crate::utils::bulk_ping; 3 | use crate::utils::{get_all_ips_v4, get_all_ips_v6}; 4 | use dialoguer::{theme::ColorfulTheme, Select}; 5 | use indicatif::ProgressBar; 6 | use std::net::IpAddr; 7 | use std::time::Duration; 8 | 9 | /// ## ping_controller 10 | /// Ping 测试 11 | pub async fn ping_controller( 12 | i18n: &I18nItems<'_>, 13 | ) -> Result, Box> { 14 | let items = vec!["IPv4", "IPv6"]; 15 | let selection = Select::with_theme(&ColorfulTheme::default()) 16 | .items(&items) 17 | .default(0) 18 | .interact()?; 19 | let mut ips = match selection { 20 | 1 => get_all_ips_v6(i18n).await?, 21 | _ => get_all_ips_v4(i18n).await?, 22 | }; 23 | let pb = ProgressBar::new(ips.len().try_into().unwrap()); 24 | println!( 25 | "{} {} {}", 26 | i18n.ping_controller_i18n.will_test_before_num, 27 | ips.len(), 28 | i18n.ping_controller_i18n.will_test_after_num 29 | ); 30 | pb.tick(); 31 | let mut result = Vec::new(); 32 | const BULK_NUM: usize = 4096; 33 | loop { 34 | if ips.len() == 0 { 35 | pb.finish(); 36 | break; 37 | } 38 | if ips.len() < BULK_NUM { 39 | let mut res = bulk_ping(ips).await?; 40 | result.append(&mut res); 41 | pb.finish(); 42 | break; 43 | } 44 | let ips_slice = ips.split_off(ips.len() - BULK_NUM); 45 | let mut res = bulk_ping(ips_slice).await?; 46 | result.append(&mut res); 47 | pb.inc(BULK_NUM.try_into().unwrap()); 48 | } 49 | result.sort_by(|a, b| a.1.cmp(&b.1)); 50 | Ok(result) 51 | } 52 | -------------------------------------------------------------------------------- /src/i18n/zh_cn.rs: -------------------------------------------------------------------------------- 1 | use crate::i18n::interface::{ 2 | ChooseIPsI18n, DownloadControllerI18n, I18nItems, MainI18n, PingControllerI18n, 3 | }; 4 | 5 | pub fn zh_cn<'a>() -> I18nItems<'a> { 6 | let download_controller_zh_cn = DownloadControllerI18n { 7 | testing: "正在测试:", 8 | total_before_num: "将对", 9 | total_after_num: "个 ip 进行下载速度测试", 10 | }; 11 | let ping_controller_zh_cn = PingControllerI18n { 12 | reading_custom_file: "从自定义 IP 文件获取 IP", 13 | reading_custom_file_error: "无法读取文件", 14 | getting_ips_from_cloudflare: "正在从 Cloudflare 获取 IP 列表", 15 | getting_ips_from_cloudflare_success: "从 Cloudflare 获取 IP 列表成功", 16 | getting_ips_from_cloudflare_failed: "从 Cloudflare 获取 IP 列表失败", 17 | choose_ips: "选择 IP 列表", 18 | internal_or_online: "Cloudflare 的在线 IPv6 地址列表中绝大多数地址不可用,使用内置列表吗?", 19 | generating_ips: "正在随机生成待 ping 的 IP 列表", 20 | prompt_part1: "请输入测试轮数 (0 ≤ x ≤ ", 21 | prompt_part2: ") (每轮 ", 22 | prompt_part3: " 个,用时 10 秒,互不重复)", 23 | invalid_input: "输入不合法", 24 | will_test_before_num: "将对", 25 | will_test_after_num: "个 ip 进行 ping 测试", 26 | }; 27 | let main_i18n = MainI18n { 28 | test_result: "测试结果:", 29 | ip: "IP:", 30 | ping: "Ping:", 31 | real_delay: "真实延迟:", 32 | download_speed: "速度:", 33 | if_save_result: "是否保存结果?", 34 | result_saved: "结果已保存至运行目录的 result.csv 下", 35 | cannot_get_dir: "无法获取程序运行目录", 36 | failed_to_write: "文件写入失败", 37 | }; 38 | let choose_ips_i18n = ChooseIPsI18n { 39 | use_original_ips: "使用内置 IP 列表", 40 | use_tested_ips: "使用测试过的 IP 列表", 41 | use_online_ips: "从 Cloudflare 获取 IP 列表", 42 | }; 43 | let zh_cn_i18n_items = I18nItems { 44 | download_controller_i18n: download_controller_zh_cn, 45 | ping_controller_i18n: ping_controller_zh_cn, 46 | real_delay_controller_i18n: "将进行真实延迟测试以获得 50 个可用 ip", 47 | choose_ips_i18n, 48 | main_i18n, 49 | }; 50 | return zh_cn_i18n_items; 51 | } 52 | -------------------------------------------------------------------------------- /src/i18n/en_us.rs: -------------------------------------------------------------------------------- 1 | use crate::i18n::interface::{ 2 | ChooseIPsI18n, DownloadControllerI18n, I18nItems, MainI18n, PingControllerI18n, 3 | }; 4 | 5 | pub fn en_us<'a>() -> I18nItems<'a> { 6 | let download_controller_i18n = DownloadControllerI18n { 7 | testing: "Testing: ", 8 | total_before_num: "Download speed test will be done on", 9 | total_after_num: "IPs", 10 | }; 11 | let ping_controller_i18n = PingControllerI18n { 12 | reading_custom_file: "Reading custom IP file", 13 | reading_custom_file_error:"Cannot read custom IP file", 14 | getting_ips_from_cloudflare: "Getting IP List from Cloudflare", 15 | getting_ips_from_cloudflare_success: "Success", 16 | getting_ips_from_cloudflare_failed: "Failed getting IP List from Cloudflare", 17 | choose_ips: "Choose IP List", 18 | internal_or_online: "Most of the addresses in Cloudflare's online IPv6 address list are not available, use the built-in list?", 19 | generating_ips: "Generating IP list...", 20 | prompt_part1: "Input test rounds (0 ≤ x ≤ ", 21 | prompt_part2: ") (each round will take 10 seconds to test ", 22 | prompt_part3: " IPs)", 23 | invalid_input: "Invalid Input", 24 | will_test_before_num: "Will ping", 25 | will_test_after_num: "IPs", 26 | }; 27 | let main_i18n = MainI18n { 28 | test_result: "Test result:", 29 | ip: "IP:", 30 | ping: "Ping:", 31 | real_delay: "Real Delay:", 32 | download_speed: "Speed:", 33 | if_save_result: "Save results?", 34 | result_saved: "Results have been saved into result.csv", 35 | cannot_get_dir: "Failed to get the program's working directory", 36 | failed_to_write: "Failed to write to file", 37 | }; 38 | let choose_ips_i18n = ChooseIPsI18n { 39 | use_original_ips: "Use original IP list", 40 | use_tested_ips: "Use tested IP list", 41 | use_online_ips: "Get IP list from Cloudflare", 42 | }; 43 | let en_us_i18n_items = I18nItems { 44 | download_controller_i18n, 45 | ping_controller_i18n, 46 | real_delay_controller_i18n: "Will test real delay to get 50 avaliable IPs", 47 | choose_ips_i18n, 48 | main_i18n, 49 | }; 50 | return en_us_i18n_items; 51 | } 52 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | mod controller; 2 | use dialoguer::{theme::ColorfulTheme, Confirm, Select}; 3 | mod data; 4 | mod i18n; 5 | mod utils; 6 | use i18n::{en_us::en_us, zh_cn::zh_cn}; 7 | 8 | #[tokio::main] 9 | async fn main() -> Result<(), Box> { 10 | utils::get_args(); // To display help info without asking language 11 | let items = vec!["简体中文", "English (US)"]; 12 | let selection = Select::with_theme(&ColorfulTheme::default()) 13 | .items(&items) 14 | .default(0) 15 | .interact()?; 16 | let i18n_items = match selection { 17 | 0 => zh_cn(), 18 | 1 => en_us(), 19 | _ => en_us(), 20 | }; 21 | let ping_res = controller::ping_controller(&i18n_items).await?; 22 | let real_delay_res = controller::real_delay_controller(ping_res, &i18n_items).await?; 23 | let download_res = controller::download_controller(real_delay_res, &i18n_items).await?; 24 | let mut cli_output_str = format!("{}\n", i18n_items.main_i18n.test_result); 25 | let mut file_output_str = String::from("IP,Ping,Real Delay,Speed (MB/s)\n"); 26 | for res in download_res { 27 | let mb_s = res.speed / 1024f64 / 1024f64; 28 | let cli_line = format!( 29 | "{} {:15}, {} {:4}, {} {:4}, {} {:.5} MB/s\n", 30 | i18n_items.main_i18n.ip, 31 | res.ip, 32 | i18n_items.main_i18n.ping, 33 | res.ping.as_millis(), 34 | i18n_items.main_i18n.real_delay, 35 | res.real_delay.as_millis(), 36 | i18n_items.main_i18n.download_speed, 37 | mb_s, 38 | ); 39 | let file_line = format!( 40 | "{},{},{},{:.5}\n", 41 | res.ip, 42 | res.ping.as_millis(), 43 | res.real_delay.as_millis(), 44 | mb_s 45 | ); 46 | cli_output_str.push_str(cli_line.as_str()); 47 | file_output_str.push_str(file_line.as_str()); 48 | } 49 | print!("{}", cli_output_str); 50 | let if_save_file = Confirm::new() 51 | .with_prompt(i18n_items.main_i18n.if_save_result) 52 | .interact()?; 53 | if if_save_file { 54 | let mut div = std::env::current_dir().expect(i18n_items.main_i18n.cannot_get_dir); 55 | div.push("result.csv"); 56 | std::fs::write(div, file_output_str).expect(i18n_items.main_i18n.failed_to_write); 57 | println!("{}", i18n_items.main_i18n.result_saved); 58 | std::thread::sleep(std::time::Duration::from_secs(3)); 59 | } 60 | Ok(()) 61 | } 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ⚡ Cloudflare Speed Test in Rust 2 | 3 | [English](README-en_US.md) 4 | 5 | ![banner](https://socialify.git.ci/lixiang810/CloudflareSpeedTest-Rust/image?description=1&font=KoHo&forks=1&issues=1&language=1&name=1&owner=1&pattern=Circuit%20Board&pulls=1&stargazers=1&theme=Dark) 6 | 7 | [![GitHub stars](https://img.shields.io/github/stars/lixiang810/cloudflare-speed-test-rust?style=for-the-badge)](https://github.com/lixiang810/cloudflare-speed-test-rust/stargazers) [![GitHub license](https://img.shields.io/github/license/lixiang810/cloudflare-speed-test-rust?style=for-the-badge)](https://github.com/lixiang810/cloudflare-speed-test-rust/blob/main/LICENSE) 8 | 9 | 用 Rust 写的 Cloudflare Speed Test,练手用。 10 | 11 | ## 🔖 下载发行版 12 | 13 | 前往[此处](https://github.com/lixiang810/cloudflare-speed-test-rust/releases/)下载。 14 | 15 | ### 📦 文件选择 16 | 17 | | 操作系统 | 文件选择 | 18 | | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------ | 19 | | Windows | `cloudflare-speed-test-rust_[版本号]_x86_64-pc-windows-gnu.zip` | 20 | | Linux | `cloudflare-speed-test-rust_[版本号]_x86_64-unknown-linux-musl.tar.xz` 或 `cloudflare-speed-test-rust_[版本号]_x86_64-unknown-linux-musl.tar.gz` | 21 | | Mac OS | `cloudflare-speed-test-rust_[版本号]_x86_64-apple-darwin.zip` | 22 | 23 | ### ⚡ 下载加速 24 | 25 | 可以参考 [GhProxy](https://ghproxy.com) 26 | 27 | ## 🏭 自构建方法 28 | 29 | ```bash 30 | git clone https://github.com/lixiang810/cloudflare-speed-test-rust 31 | cd cloudflare-speed-test-rust 32 | cargo build -r 33 | sudo ./target/release/cfst # Linux 下需要 sudo,Windows 下直接双击运行即可 34 | ``` 35 | 36 | ## 🔧 使用自定义 IP 文件 37 | 38 | ### 文件格式 39 | 40 | #### IPv4 41 | 42 | ```plaintext 43 | 173.245.48.0/20 44 | 141.101.64.0/18 45 | 131.0.72.0/22 46 | ... 47 | ``` 48 | 49 | #### IPv6 50 | 51 | ```plaintext 52 | 2606:4700:3000::/48 53 | 2606:4700:3001::/48 54 | 2606:4700:3002::/48 55 | 2606:4700:3003::/48 56 | 2606:4700:3004::/48 57 | ... 58 | ``` 59 | 60 | ### POSIX 61 | 62 | ```bash 63 | sudo cfst -c 64 | ``` 65 | 66 | ### Windows 67 | 68 | ```dos 69 | cfst.exe -c 70 | ``` 71 | 72 | ## ❤️ 鸣谢项目 / 类似项目 73 | 74 | - IBMYes(已删除)—— bash 和 bat 75 | - better-cloudflare-ip(已删除)—— bash 和 bat 76 | - [CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest) —— Go 77 | 78 | ## 🔒 隐私说明 79 | 80 | 本项目会且只会与 Cloudflare 服务器进行 https 和 icmp 通信。 81 | 82 | ## 🤯 免责声明 83 | 84 | 想干嘛就干嘛。当然,后果自负。 85 | 86 | ## 📝 特殊说明 87 | 88 | ### IPv4 的内置 IP 89 | 90 | 程序中内置了两份 IPv4 IP,其中一份会与 [Cloudflare 的 IP 列表](https://www.cloudflare.com/ips-v4)保持一致。另一份则是由一位用户发给我的,质量可能比 Cloudflare 官方的列表更高,但其获取方式与安全性都尚不明确,使用后果自负。 91 | 92 | ### IPv6 的内置 IP 93 | 94 | 与 IPv4 时一样,本项目支持从 [Cloudflare 的 IP 列表](https://www.cloudflare.com/ips-v6)获取可用 IP,但这份 IPv6 列表中绝大部分 IP 是不可用的。 95 | 96 | 我从 [CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest) 获取了一份列表并硬编码到了程序中。这份列表的可用度很高,但其获取方式与安全性都尚不明确。 97 | 98 | 介意 IP 地址安全性的可以让程序从 Cloudflare 获取 IP(推荐测试轮数设为 20 轮以上),希望效率更高的可以让程序使用内置的 IP 列表。 99 | 100 | ## 🧑‍🏭 开源协议 101 | 102 | AGPL-3.0 103 | -------------------------------------------------------------------------------- /README-en_US.md: -------------------------------------------------------------------------------- 1 | # ⚡ Cloudflare Speed Test in Rust 2 | 3 | [![GitHub stars](https://img.shields.io/github/stars/lixiang810/cloudflare-speed-test-rust?style=for-the-badge)](https://github.com/lixiang810/cloudflare-speed-test-rust/stargazers) [![GitHub license](https://img.shields.io/github/license/lixiang810/cloudflare-speed-test-rust?style=for-the-badge)](https://github.com/lixiang810/cloudflare-speed-test-rust/blob/main/LICENSE) 4 | 5 | Cloudflare Speed Test written in Rust, for my practice. 6 | 7 | ## 🔖 Download Release 8 | 9 | [Here](https://github.com/lixiang810/cloudflare-speed-test-rust/releases/) 10 | 11 | ### 📦 Choose file 12 | 13 | | OS | File to download | 14 | | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | 15 | | Windows | `cloudflare-speed-test-rust_[Version]_x86_64-pc-windows-gnu.zip` | 16 | | Linux | `cloudflare-speed-test-rust_[Version]_x86_64-unknown-linux-musl.tar.xz` or `cloudflare-speed-test-rust_[Version]_x86_64-unknown-linux-musl.tar.gz` | 17 | | Mac OS | `cloudflare-speed-test-rust_[Version]_x86_64-apple-darwin.zip` | 18 | 19 | ## 🏭 Build it yourself 20 | 21 | ```bash 22 | git clone https://github.com/lixiang810/cloudflare-speed-test-rust 23 | cd cloudflare-speed-test-rust 24 | cargo build -r 25 | sudo ./target/release/cfst # sudo if you're using Linux 26 | ``` 27 | 28 | ## 🔧 Use custom IP file 29 | 30 | ### Format 31 | 32 | #### IPv4 33 | 34 | ```plaintext 35 | 173.245.48.0/20 36 | 141.101.64.0/18 37 | 131.0.72.0/22 38 | ... 39 | ``` 40 | 41 | #### IPv6 42 | 43 | ```plaintext 44 | 2606:4700:3000::/48 45 | 2606:4700:3001::/48 46 | 2606:4700:3002::/48 47 | 2606:4700:3003::/48 48 | 2606:4700:3004::/48 49 | ... 50 | ``` 51 | 52 | ### POSIX 53 | 54 | ```bash 55 | sudo cfst -c 56 | ``` 57 | 58 | ### Windows 59 | 60 | ```dos 61 | cfst.exe -c 62 | ``` 63 | 64 | ## ❤️ Thanks 65 | 66 | - IBMYes(deleted)-- bash and bat 67 | - better-cloudflare-ip(deleted)-- bash and bat 68 | - [CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest) -- Go 69 | 70 | ## 🔒 Privacy 71 | 72 | This program will and will only communicate with the Cloudflare server with HTTPS and ICMP Protocol. 73 | 74 | ## 🤯 Disclaimer 75 | 76 | Do anything with it at your own risk. 77 | 78 | ## 📝 Special Notes 79 | 80 | ### For IPv4 81 | 82 | There are two copies of IPv4 IPs built into the program, one of which will be consistent with [Cloudflare's IP list](https://www.cloudflare.com/ips-v4). The other one was sent to me by a user, and may be of higher quality than Cloudflare's official list, but its access and security are not yet clear, so use at your own risk. 83 | 84 | ### For IPv6 85 | 86 | As with IPv4, the project supports getting available IPs from [Cloudflare's IP list](https://www.cloudflare.com/ips-v6), but the vast majority of IPs in this IPv6 list are not available. 87 | 88 | I got a list from [CloudflareSpeedTest](https://github.com/XIU2/CloudflareSpeedTest) and hardcoded it into the program. This list is very available, but its access and security are not clear. 89 | 90 | If you are concerned about IP address security, you can let the program get IPs from Cloudflare (recommended test rounds are set to 20 or more), and if you want to be more efficient, you can let the program use the built-in IP list. 91 | 92 | ## 🧑‍🏭 LICENSE 93 | 94 | AGPL-3.0 95 | -------------------------------------------------------------------------------- /src/utils/ipv6_range.rs: -------------------------------------------------------------------------------- 1 | use ipnet::Ipv6Net; 2 | use rand::{ 3 | prelude::{thread_rng, SeedableRng, SmallRng}, 4 | Rng, 5 | }; 6 | use std::net::IpAddr; 7 | 8 | /// # IPv6Range 9 | /// 我知道,我代码写得很屎,不会搞比较高级的位操作,只好土法炼钢了。 10 | /// 11 | /// 这个对象从一个 Ipv6Net 构建,并提供名为 `get_random_ip` 的方法来从这个 IP 段随机获取一个 IP。 12 | pub struct IPv6Range { 13 | prefix_length: usize, 14 | network_str: String, 15 | rng: SmallRng, 16 | } 17 | 18 | impl IPv6Range { 19 | pub fn new(ipv6_net: Ipv6Net) -> IPv6Range { 20 | let mut thread_rng = thread_rng(); 21 | IPv6Range { 22 | prefix_length: ipv6_net.prefix_len() as usize, 23 | network_str: format!("{}", ipv6_net.network()).replace(":", ""), 24 | rng: SmallRng::from_rng(&mut thread_rng).unwrap(), 25 | } 26 | } 27 | fn get_bit_ary_from_letter(letter: char) -> [bool; 4] { 28 | match letter { 29 | '0' => [false, false, false, false], 30 | '1' => [false, false, false, true], 31 | '2' => [false, false, true, false], 32 | '3' => [false, false, true, true], 33 | '4' => [false, true, false, false], 34 | '5' => [false, true, false, true], 35 | '6' => [false, true, true, false], 36 | '7' => [false, true, true, true], 37 | '8' => [true, false, false, false], 38 | '9' => [true, false, false, true], 39 | 'a' => [true, false, true, false], 40 | 'b' => [true, false, true, true], 41 | 'c' => [true, true, false, false], 42 | 'd' => [true, true, false, true], 43 | 'e' => [true, true, true, false], 44 | 'f' => [true, true, true, true], 45 | _ => [false, false, false, false], 46 | } 47 | } 48 | fn get_letter_from_bit_ary(bit_ary: [bool; 4]) -> char { 49 | match bit_ary { 50 | [false, false, false, false] => '0', 51 | [false, false, false, true] => '1', 52 | [false, false, true, false] => '2', 53 | [false, false, true, true] => '3', 54 | [false, true, false, false] => '4', 55 | [false, true, false, true] => '5', 56 | [false, true, true, false] => '6', 57 | [false, true, true, true] => '7', 58 | [true, false, false, false] => '8', 59 | [true, false, false, true] => '9', 60 | [true, false, true, false] => 'a', 61 | [true, false, true, true] => 'b', 62 | [true, true, false, false] => 'c', 63 | [true, true, false, true] => 'd', 64 | [true, true, true, false] => 'e', 65 | [true, true, true, true] => 'f', 66 | } 67 | } 68 | fn get_bit_ary(&self) -> [bool; 128] { 69 | let mut bit_ary = [false; 128]; 70 | let chars: Vec = self.network_str.chars().collect(); 71 | for i in 0..chars.len() { 72 | let slice = &mut bit_ary[i * 4..i * 4 + 4]; 73 | let bit_slice = IPv6Range::get_bit_ary_from_letter(chars[i]); 74 | [slice[0], slice[1], slice[2], slice[3]] = bit_slice; 75 | } 76 | return bit_ary; 77 | } 78 | fn get_random_ip_bit_ary(&mut self) -> [bool; 128] { 79 | let mut bit_ary = self.get_bit_ary(); 80 | let mut rand_ary = [false; 128]; 81 | self.rng.fill(&mut rand_ary); 82 | for i in self.prefix_length..bit_ary.len() { 83 | bit_ary[i] = rand_ary[i]; 84 | } 85 | return bit_ary; 86 | } 87 | pub fn get_random_ip(&mut self) -> IpAddr { 88 | let bit_ary = self.get_random_ip_bit_ary(); 89 | let mut string = String::new(); 90 | for i in 0..32 { 91 | let j = i * 4; 92 | let letter = IPv6Range::get_letter_from_bit_ary([ 93 | bit_ary[j], 94 | bit_ary[j + 1], 95 | bit_ary[j + 2], 96 | bit_ary[j + 3], 97 | ]); 98 | string.push(letter); 99 | if (i % 4 == 3) && (i != 31) { 100 | string.push(':') 101 | } 102 | } 103 | return IpAddr::V6(string.parse().unwrap()); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/utils/get_all_ips.rs: -------------------------------------------------------------------------------- 1 | use crate::data::{IPV4_IPS_ORIGINAL, IPV4_IPS_TESTED, IPV6_IPS}; 2 | use crate::i18n::interface::I18nItems; 3 | use crate::utils::{get_args, IPv6Range}; 4 | use async_recursion::async_recursion; 5 | use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select}; 6 | use indicatif::ProgressBar; 7 | use ipnet::{Ipv4Net, Ipv6Net}; 8 | use iprange::IpRange; 9 | use random_number::random; 10 | use std::collections::HashSet; 11 | use std::net::{IpAddr, Ipv4Addr}; 12 | use std::time::Duration; 13 | 14 | /// 每轮的 IP 数量 15 | const IP_CHUNK: u64 = 4096; 16 | 17 | /// ## input_num_of_ips 18 | /// 让用户输入想测试的轮数 19 | fn input_num_of_ips(max: u64, i18n: &I18nItems<'_>) -> u64 { 20 | Input::new() 21 | .with_prompt::(format!( 22 | "{}{}{}{}{}", 23 | i18n.ping_controller_i18n.prompt_part1, 24 | (max / IP_CHUNK) + 1, 25 | i18n.ping_controller_i18n.prompt_part2, 26 | IP_CHUNK, 27 | i18n.ping_controller_i18n.prompt_part3, 28 | )) 29 | .default(1) 30 | .validate_with(|input: &u64| -> Result<(), &str> { 31 | if (max / IP_CHUNK) + 1 < *input { 32 | return Err(i18n.ping_controller_i18n.invalid_input); 33 | } 34 | Ok(()) 35 | }) 36 | .interact_text() 37 | .expect(i18n.ping_controller_i18n.invalid_input) 38 | } 39 | 40 | #[async_recursion] 41 | async fn choose_ipv4_ips(i18n: &I18nItems<'_>) -> Result> { 42 | let items = vec![ 43 | i18n.choose_ips_i18n.use_online_ips, 44 | i18n.choose_ips_i18n.use_original_ips, 45 | i18n.choose_ips_i18n.use_tested_ips, 46 | ]; 47 | let selection = Select::with_theme(&ColorfulTheme::default()) 48 | .items(&items) 49 | .default(0) 50 | .interact() 51 | .expect(i18n.ping_controller_i18n.invalid_input); 52 | let res = match selection { 53 | 0 => { 54 | let client = reqwest::ClientBuilder::new() 55 | .timeout(Duration::from_secs(5)) 56 | .build()?; 57 | let online_ips_res = client.get("https://www.cloudflare.com/ips-v4").send().await; 58 | if let Ok(res) = online_ips_res { 59 | let ips_str = res.text().await?; 60 | ips_str 61 | } else { 62 | println!( 63 | "{}", 64 | i18n.ping_controller_i18n.getting_ips_from_cloudflare_failed 65 | ); 66 | choose_ipv4_ips(i18n).await? 67 | } 68 | } 69 | 1 => IPV4_IPS_ORIGINAL.to_string(), 70 | 2 => IPV4_IPS_TESTED.to_string(), 71 | _ => IPV4_IPS_ORIGINAL.to_string(), 72 | }; 73 | Ok(res) 74 | } 75 | 76 | /// ## get_all_ips_v4 77 | /// 获取 IPv4 IP,并返回 78 | pub async fn get_all_ips_v4( 79 | i18n: &I18nItems<'_>, 80 | ) -> Result, Box> { 81 | let args = get_args(); 82 | let txt = match args.custom_ip_file { 83 | Some(route) => { 84 | println!( 85 | "{}: {}", 86 | i18n.ping_controller_i18n.reading_custom_file, route 87 | ); 88 | std::fs::read_to_string(route).expect(i18n.ping_controller_i18n.reading_custom_file_error) 89 | } 90 | None => choose_ipv4_ips(i18n).await?, 91 | }; 92 | let ip_range: IpRange = txt 93 | .trim() 94 | .split("\n") 95 | .map(|s| { 96 | let mut st = String::from(s); 97 | if !st.contains("/") { 98 | st.push_str("/32"); 99 | } 100 | st.parse().unwrap() 101 | }) 102 | .collect(); 103 | // Disable simplify to make custom ranks possible. 104 | // ip_range.simplify(); 105 | let mut ips_vec_temp: Vec = ip_range 106 | .iter() 107 | .flat_map(|ipv4_net| ipv4_net.hosts()) 108 | .collect(); 109 | let mut ips_vec = Vec::new(); 110 | let rand_num = input_num_of_ips(ips_vec_temp.len() as u64, i18n); 111 | for _ in 0..(rand_num * IP_CHUNK) { 112 | let len = ips_vec_temp.len(); 113 | if len <= 0 { 114 | break; 115 | } 116 | ips_vec.push(IpAddr::V4(ips_vec_temp.swap_remove(random!(0..len)))) 117 | } 118 | return Ok(ips_vec); 119 | } 120 | 121 | /// ## get_all_ips_v6 122 | /// 获取 IPv6 IP,并返回 123 | pub async fn get_all_ips_v6( 124 | i18n: &I18nItems<'_>, 125 | ) -> Result, Box> { 126 | let args = get_args(); 127 | let txt = match args.custom_ip_file { 128 | Some(route) => { 129 | println!( 130 | "{}: {}", 131 | i18n.ping_controller_i18n.reading_custom_file, route 132 | ); 133 | std::fs::read_to_string(route).expect(i18n.ping_controller_i18n.reading_custom_file_error) 134 | } 135 | None => { 136 | let if_internal = Confirm::new() 137 | .with_prompt(i18n.ping_controller_i18n.internal_or_online) 138 | .interact()?; 139 | if if_internal { 140 | IPV6_IPS.to_string() 141 | } else { 142 | let client = reqwest::ClientBuilder::new() 143 | .timeout(Duration::from_secs(5)) 144 | .build()?; 145 | let cf_ips = client.get("https://www.cloudflare.com/ips-v6").send().await; 146 | println!("{}", i18n.ping_controller_i18n.getting_ips_from_cloudflare); 147 | let res = if let Ok(res) = cf_ips { 148 | println!( 149 | "{}", 150 | i18n 151 | .ping_controller_i18n 152 | .getting_ips_from_cloudflare_success 153 | ); 154 | res.text().await? 155 | } else { 156 | println!( 157 | "{}", 158 | i18n.ping_controller_i18n.getting_ips_from_cloudflare_failed 159 | ); 160 | IPV6_IPS.to_string() 161 | }; 162 | res 163 | } 164 | } 165 | }; 166 | let ip_range: IpRange = txt 167 | .trim() 168 | .split("\n") 169 | .map(|s| { 170 | let mut st = String::from(s); 171 | if !st.contains("/") { 172 | st.push_str("/128"); 173 | } 174 | st.parse().unwrap() 175 | }) 176 | .collect(); 177 | // Disable simplify to make custom ranks possible. 178 | // ip_range.simplify(); 179 | let mut ipv6_net_vec = ip_range 180 | .iter() 181 | .map(|ipv6_net| IPv6Range::new(ipv6_net)) 182 | .collect::>(); 183 | let mut total_length = 0u64; 184 | ip_range.iter().for_each(|ipv6_net| { 185 | total_length = 186 | total_length.saturating_add(2u64.saturating_pow(128u32 - (ipv6_net.prefix_len() as u32))); 187 | }); 188 | let rand_num = input_num_of_ips(total_length, i18n); 189 | let mut rand_ips_hashset = HashSet::new(); 190 | let pb = ProgressBar::new((rand_num * IP_CHUNK).try_into().unwrap()); 191 | pb.tick(); 192 | pb.println(i18n.ping_controller_i18n.generating_ips); 193 | let mut conflict_count = 0; 194 | while (rand_ips_hashset.len() as u64) < (rand_num * IP_CHUNK) { 195 | if conflict_count >= 1000 { 196 | break; 197 | } 198 | let len = ipv6_net_vec.len(); 199 | let rand_ip = ipv6_net_vec[random!(0..len)].get_random_ip(); 200 | if !rand_ips_hashset.contains(&rand_ip) { 201 | rand_ips_hashset.insert(rand_ip); 202 | pb.inc(1); 203 | } else { 204 | conflict_count += 1; 205 | } 206 | } 207 | pb.finish(); 208 | return Ok(rand_ips_hashset.iter().map(|ele| *ele).collect()); 209 | } 210 | -------------------------------------------------------------------------------- /src/data/ips.rs: -------------------------------------------------------------------------------- 1 | /// 内置 IPv4 IP 列表,与 [Cloudflare 在线列表](https://www.cloudflare.com/ips-v4)保持一致 2 | pub const IPV4_IPS_ORIGINAL: &str = r#"173.245.48.0/20 3 | 103.21.244.0/22 4 | 103.22.200.0/22 5 | 103.31.4.0/22 6 | 141.101.64.0/18 7 | 108.162.192.0/18 8 | 190.93.240.0/20 9 | 188.114.96.0/20 10 | 197.234.240.0/22 11 | 198.41.128.0/17 12 | 162.158.0.0/15 13 | 104.16.0.0/13 14 | 104.24.0.0/14 15 | 172.64.0.0/13 16 | 131.0.72.0/22 17 | "#; 18 | 19 | pub const IPV4_IPS_TESTED: &str = r#"1.0.0.0/24 20 | 1.1.1.0/24 21 | 5.101.36.0/24 22 | 5.101.39.0/24 23 | 5.226.179.0/24 24 | 5.252.118.0/24 25 | 8.6.112.0/24 26 | 8.6.144.0/23 27 | 8.6.146.0/24 28 | 8.9.230.0/23 29 | 8.10.148.0/24 30 | 8.14.199.0/24 31 | 8.14.201.0/24 32 | 8.14.202.0/23 33 | 8.14.204.0/24 34 | 8.17.205.0/24 35 | 8.17.206.0/24 36 | 8.17.207.0/24 37 | 8.18.50.0/24 38 | 8.18.113.0/24 39 | 8.18.194.0/23 40 | 8.18.196.0/24 41 | 8.20.100.0/23 42 | 8.20.103.0/24 43 | 8.20.122.0/23 44 | 8.20.124.0/22 45 | 8.20.253.0/24 46 | 8.21.8.0/22 47 | 8.21.13.0/24 48 | 8.21.110.0/23 49 | 8.21.238.0/23 50 | 8.23.139.0/24 51 | 8.23.240.0/24 52 | 8.24.87.0/24 53 | 8.24.242.0/23 54 | 8.24.244.0/24 55 | 8.25.96.0/23 56 | 8.25.249.0/24 57 | 8.26.176.0/24 58 | 8.26.180.0/24 59 | 8.26.182.0/24 60 | 8.27.64.0/24 61 | 8.27.66.0/23 62 | 8.27.68.0/23 63 | 8.27.70.0/24 64 | 8.28.20.0/24 65 | 8.28.82.0/24 66 | 8.28.126.0/23 67 | 8.28.213.0/24 68 | 8.29.105.0/24 69 | 8.29.109.0/24 70 | 8.29.228.0/24 71 | 8.29.230.0/23 72 | 8.30.234.0/24 73 | 8.31.2.0/24 74 | 8.31.160.0/24 75 | 8.31.163.0/24 76 | 8.34.69.0/24 77 | 8.34.70.0/23 78 | 8.34.200.0/23 79 | 8.34.202.0/24 80 | 8.35.57.0/24 81 | 8.35.58.0/23 82 | 8.35.149.0/24 83 | 8.35.211.0/24 84 | 8.36.216.0/23 85 | 8.36.218.0/24 86 | 8.36.220.0/24 87 | 8.37.41.0/24 88 | 8.37.43.0/24 89 | 8.38.147.0/24 90 | 8.38.148.0/23 91 | 8.38.172.0/24 92 | 8.39.6.0/24 93 | 8.39.18.0/24 94 | 8.39.125.0/24 95 | 8.39.126.0/23 96 | 8.39.201.0/24 97 | 8.39.202.0/23 98 | 8.39.204.0/22 99 | 8.39.212.0/22 100 | 8.40.26.0/23 101 | 8.40.28.0/22 102 | 8.40.107.0/24 103 | 8.40.111.0/24 104 | 8.40.140.0/24 105 | 8.41.5.0/24 106 | 8.41.6.0/23 107 | 8.41.36.0/23 108 | 8.42.51.0/24 109 | 8.42.52.0/24 110 | 8.42.54.0/23 111 | 8.42.161.0/24 112 | 8.42.164.0/24 113 | 8.42.172.0/24 114 | 8.42.245.0/24 115 | 8.43.121.0/24 116 | 8.43.122.0/23 117 | 8.43.224.0/23 118 | 8.43.226.0/24 119 | 8.44.0.0/22 120 | 8.44.6.0/24 121 | 8.44.58.0/23 122 | 8.44.60.0/22 123 | 8.45.41.0/24 124 | 8.45.42.0/23 125 | 8.45.44.0/22 126 | 8.45.97.0/24 127 | 8.45.100.0/23 128 | 8.45.102.0/24 129 | 8.45.108.0/24 130 | 8.45.111.0/24 131 | 8.45.144.0/22 132 | 8.45.151.0/24 133 | 8.46.113.0/24 134 | 8.46.114.0/23 135 | 8.46.117.0/24 136 | 8.46.118.0/23 137 | 8.47.9.0/24 138 | 8.47.12.0/22 139 | 8.47.69.0/24 140 | 8.47.71.0/24 141 | 8.48.130.0/24 142 | 8.48.131.0/24 143 | 8.48.132.0/23 144 | 8.48.134.0/24 145 | 12.221.133.0/24 146 | 23.227.37.0/24 147 | 23.227.38.0/23 148 | 31.43.179.0/24 149 | 38.67.242.0/24 150 | 45.8.104.0/22 151 | 45.8.211.0/24 152 | 45.12.30.0/23 153 | 45.14.174.0/24 154 | 45.85.118.0/23 155 | 45.95.241.0/24 156 | 45.131.4.0/22 157 | 45.131.208.0/22 158 | 45.133.246.0/23 159 | 45.142.120.0/24 160 | 45.145.28.0/23 161 | 45.159.216.0/22 162 | 64.68.192.0/24 163 | 65.110.63.0/24 164 | 65.205.150.0/24 165 | 66.235.200.0/24 166 | 68.67.65.0/24 167 | 72.52.113.0/24 168 | 80.94.83.0/24 169 | 89.47.56.0/23 170 | 89.207.18.0/24 171 | 91.192.107.0/24 172 | 91.193.59.0/24 173 | 91.199.81.0/24 174 | 91.221.116.0/24 175 | 91.226.97.0/24 176 | 91.234.214.0/24 177 | 91.243.35.0/24 178 | 93.114.64.0/23 179 | 103.11.214.0/24 180 | 103.21.244.0/24 181 | 103.21.245.0/24 182 | 103.21.246.0/23 183 | 103.22.200.0/23 184 | 103.22.202.0/24 185 | 103.22.203.0/24 186 | 103.31.4.0/22 187 | 103.81.228.0/24 188 | 103.156.22.0/23 189 | 103.160.204.0/24 190 | 103.169.142.0/24 191 | 103.172.111.0/24 192 | 103.204.13.0/24 193 | 103.244.116.0/22 194 | 104.16.0.0/13 195 | 104.24.0.0/14 196 | 104.28.0.0/15 197 | 104.30.0.0/24 198 | 104.30.1.0/24 199 | 104.30.2.0/23 200 | 104.30.4.0/22 201 | 104.30.8.0/21 202 | 104.30.16.0/20 203 | 104.30.32.0/19 204 | 104.30.64.0/18 205 | 104.30.128.0/17 206 | 104.31.0.0/16 207 | 104.254.140.0/24 208 | 108.162.192.0/18 209 | 108.165.216.0/24 210 | 109.238.160.0/21 211 | 141.101.64.0/21 212 | 141.101.72.0/22 213 | 141.101.76.0/23 214 | 141.101.78.0/23 215 | 141.101.80.0/23 216 | 141.101.82.0/23 217 | 141.101.84.0/23 218 | 141.101.86.0/23 219 | 141.101.88.0/23 220 | 141.101.90.0/24 221 | 141.101.91.0/24 222 | 141.101.92.0/23 223 | 141.101.94.0/23 224 | 141.101.96.0/21 225 | 141.101.104.0/22 226 | 141.101.108.0/23 227 | 141.101.110.0/24 228 | 141.101.111.0/24 229 | 141.101.112.0/20 230 | 141.193.213.0/24 231 | 146.19.22.0/24 232 | 147.78.140.0/24 233 | 147.185.161.0/24 234 | 154.83.2.0/24 235 | 154.83.22.0/24 236 | 154.83.31.0/24 237 | 154.84.18.0/24 238 | 154.84.20.0/24 239 | 154.84.23.0/24 240 | 154.84.175.0/24 241 | 154.85.9.0/24 242 | 156.237.5.0/24 243 | 156.238.14.0/24 244 | 156.238.18.0/24 245 | 159.112.235.0/24 246 | 162.44.104.0/22 247 | 162.158.0.0/18 248 | 162.158.64.0/21 249 | 162.158.72.0/21 250 | 162.158.80.0/20 251 | 162.158.96.0/19 252 | 162.158.128.0/17 253 | 162.159.0.0/18 254 | 162.159.64.0/21 255 | 162.159.72.0/22 256 | 162.159.76.0/23 257 | 162.159.78.0/24 258 | 162.159.79.0/24 259 | 162.159.80.0/20 260 | 162.159.96.0/19 261 | 162.159.128.0/17 262 | 162.247.243.0/24 263 | 162.251.82.0/24 264 | 168.100.6.0/24 265 | 172.64.0.0/14 266 | 172.68.0.0/16 267 | 172.69.0.0/20 268 | 172.69.16.0/21 269 | 172.69.24.0/21 270 | 172.69.32.0/19 271 | 172.69.64.0/18 272 | 172.69.128.0/18 273 | 172.69.192.0/20 274 | 172.69.208.0/24 275 | 172.69.209.0/24 276 | 172.69.210.0/23 277 | 172.69.212.0/22 278 | 172.69.216.0/21 279 | 172.69.224.0/19 280 | 172.70.0.0/19 281 | 172.70.32.0/19 282 | 172.70.64.0/20 283 | 172.70.80.0/20 284 | 172.70.96.0/19 285 | 172.70.128.0/17 286 | 172.71.0.0/16 287 | 173.245.48.0/21 288 | 173.245.56.0/22 289 | 173.245.60.0/23 290 | 173.245.62.0/23 291 | 174.136.134.0/24 292 | 176.126.206.0/23 293 | 185.18.250.0/24 294 | 185.67.124.0/24 295 | 185.72.49.0/24 296 | 185.109.21.0/24 297 | 185.122.0.0/24 298 | 185.122.1.0/24 299 | 185.122.2.0/23 300 | 185.146.172.0/24 301 | 185.148.104.0/23 302 | 185.148.106.0/24 303 | 185.162.228.0/22 304 | 185.170.166.0/24 305 | 185.171.230.0/23 306 | 185.174.138.0/24 307 | 185.176.26.0/24 308 | 185.193.28.0/22 309 | 185.201.139.0/24 310 | 185.207.92.0/24 311 | 185.212.145.0/24 312 | 185.212.146.0/23 313 | 185.213.240.0/24 314 | 185.221.160.0/24 315 | 185.223.154.0/24 316 | 185.234.22.0/24 317 | 185.235.180.0/22 318 | 185.238.228.0/24 319 | 188.114.96.0/22 320 | 188.114.100.0/24 321 | 188.114.101.0/24 322 | 188.114.102.0/23 323 | 188.114.104.0/23 324 | 188.114.106.0/23 325 | 188.114.108.0/22 326 | 188.244.122.0/24 327 | 190.93.240.0/20 328 | 191.101.251.0/24 329 | 192.133.11.0/24 330 | 193.9.49.0/24 331 | 193.16.63.0/24 332 | 193.67.144.0/24 333 | 193.188.14.0/24 334 | 193.227.99.0/24 335 | 194.1.194.0/24 336 | 194.36.49.0/24 337 | 194.36.55.0/24 338 | 194.36.208.0/23 339 | 194.36.216.0/22 340 | 194.40.240.0/23 341 | 194.53.53.0/24 342 | 194.53.55.0/24 343 | 194.87.58.0/23 344 | 194.152.44.0/24 345 | 194.169.194.0/24 346 | 195.85.23.0/24 347 | 195.85.59.0/24 348 | 195.85.88.0/24 349 | 195.88.213.0/24 350 | 195.137.167.0/24 351 | 195.242.122.0/23 352 | 195.245.221.0/24 353 | 196.13.241.0/24 354 | 196.207.45.0/24 355 | 197.234.240.0/22 356 | 198.41.128.0/23 357 | 198.41.130.0/24 358 | 198.41.131.0/24 359 | 198.41.132.0/22 360 | 198.41.136.0/22 361 | 198.41.140.0/22 362 | 198.41.144.0/22 363 | 198.41.148.0/22 364 | 198.41.152.0/22 365 | 198.41.156.0/22 366 | 198.41.160.0/19 367 | 198.41.192.0/19 368 | 198.41.224.0/21 369 | 198.41.232.0/23 370 | 198.41.234.0/24 371 | 198.41.235.0/24 372 | 198.41.236.0/22 373 | 198.41.240.0/23 374 | 198.41.242.0/24 375 | 198.41.243.0/24 376 | 198.41.244.0/22 377 | 198.41.248.0/22 378 | 198.41.252.0/23 379 | 198.41.254.0/23 380 | 198.217.251.0/24 381 | 199.27.128.0/21 382 | 199.60.103.0/24 383 | 199.181.197.0/24 384 | 202.45.130.0/24 385 | 203.13.32.0/24 386 | 203.17.126.0/24 387 | 203.22.223.0/24 388 | 203.23.103.0/24 389 | 203.23.104.0/24 390 | 203.23.106.0/24 391 | 203.24.102.0/23 392 | 203.24.108.0/23 393 | 203.28.8.0/23 394 | 203.29.52.0/22 395 | 203.30.188.0/22 396 | 203.32.120.0/23 397 | 203.34.28.0/24 398 | 203.34.80.0/24 399 | 203.55.107.0/24 400 | 203.107.173.0/24 401 | 203.193.21.0/24 402 | 204.62.141.0/24 403 | 204.68.111.0/24 404 | 206.196.23.0/24 405 | 207.189.149.0/24 406 | 208.100.60.0/24 407 | 212.24.127.0/24 408 | 212.110.134.0/23 409 | "#; 410 | 411 | /// 内置 IPv6 IP 列表,与 [Cloudflare 在线列表](https://www.cloudflare.com/ips-v6)不一致 412 | pub const IPV6_IPS: &str = r#"2606:4700:3000::/48 413 | 2606:4700:3001::/48 414 | 2606:4700:3002::/48 415 | 2606:4700:3003::/48 416 | 2606:4700:3004::/48 417 | 2606:4700:3005::/48 418 | 2606:4700:3006::/48 419 | 2606:4700:3007::/48 420 | 2606:4700:3008::/48 421 | 2606:4700:3009::/48 422 | 2606:4700:3010::/48 423 | 2606:4700:3011::/48 424 | 2606:4700:3012::/48 425 | 2606:4700:3013::/48 426 | 2606:4700:3014::/48 427 | 2606:4700:3015::/48 428 | 2606:4700:3016::/48 429 | 2606:4700:3017::/48 430 | 2606:4700:3018::/48 431 | 2606:4700:3019::/48 432 | 2606:4700:3020::/48 433 | 2606:4700:3021::/48 434 | 2606:4700:3022::/48 435 | 2606:4700:3023::/48 436 | 2606:4700:3024::/48 437 | 2606:4700:3025::/48 438 | 2606:4700:3026::/48 439 | 2606:4700:3027::/48 440 | 2606:4700:3028::/48 441 | 2606:4700:3029::/48 442 | 2606:4700:3030::/48 443 | 2606:4700:3031::/48 444 | 2606:4700:3032::/48 445 | 2606:4700:3033::/48 446 | 2606:4700:3034::/48 447 | 2606:4700:3035::/48 448 | 2606:4700:3036::/48 449 | 2606:4700:3037::/48 450 | 2606:4700:3038::/48 451 | 2606:4700:3039::/48 452 | "#; 453 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published 637 | by the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | --------------------------------------------------------------------------------