first commit

This commit is contained in:
sim1222 2025-01-15 01:47:47 +09:00
commit fb5e0c7aef
Signed by: sim1222
GPG Key ID: D1AE30E316E44E5D
7 changed files with 3030 additions and 0 deletions

5
.env.example Normal file
View File

@ -0,0 +1,5 @@
BUCKET_NAME=
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_REGION=
AWS_ENDPOINT_URL_S3=

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/target
.env
result.json

2769
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

13
Cargo.toml Normal file
View File

@ -0,0 +1,13 @@
[package]
name = "twimg-test"
version = "0.1.0"
edition = "2021"
[dependencies]
aws-config = { version = "1.5.13", features = ["behavior-version-latest"] }
aws-sdk-s3 = "1.68.0"
dotenvy = "0.15.7"
reqwest = { version = "0.12.12", features = ["rustls-tls"] }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
tokio = { version = "1.43.0", features = ["full"] }

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM rust:1.84 as builder
WORKDIR /usr/src/app
COPY . .
RUN cargo install --path .
FROM debian:bookworm-slim
COPY --from=builder /usr/local/cargo/bin/twimg-test /usr/local/bin/twimg-test
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
WORKDIR /app
CMD ["bash", "-c", "while :; do twimg-test; sleep 60; done"]

11
compose.yaml Normal file
View File

@ -0,0 +1,11 @@
services:
twimg-test:
image: sim1222/twimg-test:latest
build: .
restart: always
networks:
- v6
env_file: .env
networks:
v6:
enable_ipv6: true

219
src/main.rs Normal file
View File

@ -0,0 +1,219 @@
use std::{
env,
net::Ipv6Addr,
time::{Duration, SystemTime},
};
use dotenvy::dotenv;
use reqwest::Response;
use serde::{Deserialize, Serialize};
use tokio::{fs, time::Instant};
#[tokio::main]
async fn main() {
dotenv();
let ips: Vec<Ipv6Addr> = vec![
"2a04:4e42:1000::159".parse().unwrap(),
"2a04:4e42:11::159".parse().unwrap(),
"2a04:4e42:12::159".parse().unwrap(),
"2a04:4e42:13::159".parse().unwrap(),
"2a04:4e42:14::159".parse().unwrap(),
"2a04:4e42:15::159".parse().unwrap(),
"2a04:4e42:16::159".parse().unwrap(),
"2a04:4e42:17::159".parse().unwrap(),
"2a04:4e42:19::159".parse().unwrap(),
"2a04:4e42:1a::159".parse().unwrap(),
"2a04:4e42:1b::159".parse().unwrap(),
"2a04:4e42:1c::159".parse().unwrap(),
"2a04:4e42:1d::159".parse().unwrap(),
"2a04:4e42:1e::159".parse().unwrap(),
"2a04:4e42:1f::159".parse().unwrap(),
"2a04:4e42:2000::159".parse().unwrap(),
"2a04:4e42:200::159".parse().unwrap(),
"2a04:4e42:20::159".parse().unwrap(),
"2a04:4e42:21::159".parse().unwrap(),
"2a04:4e42:22::159".parse().unwrap(),
"2a04:4e42:23::159".parse().unwrap(),
"2a04:4e42:24::159".parse().unwrap(),
"2a04:4e42:2::159".parse().unwrap(),
"2a04:4e42:25::159".parse().unwrap(),
"2a04:4e42:26::159".parse().unwrap(),
"2a04:4e42:27::159".parse().unwrap(),
"2a04:4e42:29::159".parse().unwrap(),
"2a04:4e42:2a::159".parse().unwrap(),
"2a04:4e42:2b::159".parse().unwrap(),
"2a04:4e42:2d::159".parse().unwrap(),
"2a04:4e42:2e::159".parse().unwrap(),
"2a04:4e42:2f::159".parse().unwrap(),
"2a04:4e42:3000::159".parse().unwrap(),
"2a04:4e42:30::159".parse().unwrap(),
"2a04:4e42:32::159".parse().unwrap(),
"2a04:4e42:33::159".parse().unwrap(),
"2a04:4e42:34::159".parse().unwrap(),
"2a04:4e42:3::159".parse().unwrap(),
"2a04:4e42:35::159".parse().unwrap(),
"2a04:4e42:37::159".parse().unwrap(),
"2a04:4e42:38::159".parse().unwrap(),
"2a04:4e42:39::159".parse().unwrap(),
"2a04:4e42:3a::159".parse().unwrap(),
"2a04:4e42:3b::159".parse().unwrap(),
"2a04:4e42:4000::159".parse().unwrap(),
"2a04:4e42:400::159".parse().unwrap(),
"2a04:4e42:4039::159".parse().unwrap(),
"2a04:4e42:41::159".parse().unwrap(),
"2a04:4e42:42::159".parse().unwrap(),
"2a04:4e42:43::159".parse().unwrap(),
"2a04:4e42:44::159".parse().unwrap(),
"2a04:4e42:4::159".parse().unwrap(),
"2a04:4e42:46::159".parse().unwrap(),
"2a04:4e42:47::159".parse().unwrap(),
"2a04:4e42:48::159".parse().unwrap(),
"2a04:4e42:49::159".parse().unwrap(),
"2a04:4e42:4a::159".parse().unwrap(),
"2a04:4e42:4b::159".parse().unwrap(),
"2a04:4e42:4c::159".parse().unwrap(),
"2a04:4e42:4d::159".parse().unwrap(),
"2a04:4e42:4e::159".parse().unwrap(),
"2a04:4e42:4f::159".parse().unwrap(),
"2a04:4e42:5000::159".parse().unwrap(),
"2a04:4e42:50::159".parse().unwrap(),
"2a04:4e42:51::159".parse().unwrap(),
"2a04:4e42:52::159".parse().unwrap(),
"2a04:4e42:54::159".parse().unwrap(),
"2a04:4e42:5::159".parse().unwrap(),
"2a04:4e42:56::159".parse().unwrap(),
"2a04:4e42:58::159".parse().unwrap(),
"2a04:4e42:59::159".parse().unwrap(),
"2a04:4e42:5a::159".parse().unwrap(),
"2a04:4e42:600::159".parse().unwrap(),
"2a04:4e42:6012::159".parse().unwrap(),
"2a04:4e42:6015::159".parse().unwrap(),
"2a04:4e42:601a::159".parse().unwrap(),
"2a04:4e42:6048::159".parse().unwrap(),
"2a04:4e42:6069::159".parse().unwrap(),
"2a04:4e42:6076::159".parse().unwrap(),
"2a04:4e42:608c::159".parse().unwrap(),
"2a04:4e42:61::159".parse().unwrap(),
"2a04:4e42:62::159".parse().unwrap(),
"2a04:4e42:64::159".parse().unwrap(),
"2a04:4e42:66::159".parse().unwrap(),
"2a04:4e42:69::159".parse().unwrap(),
"2a04:4e42:6a::159".parse().unwrap(),
"2a04:4e42:6f::159".parse().unwrap(),
"2a04:4e42:7000::159".parse().unwrap(),
"2a04:4e42:70::159".parse().unwrap(),
"2a04:4e42:71::159".parse().unwrap(),
"2a04:4e42:72::159".parse().unwrap(),
"2a04:4e42:73::159".parse().unwrap(),
"2a04:4e42:74::159".parse().unwrap(),
"2a04:4e42:7::159".parse().unwrap(),
"2a04:4e42:75::159".parse().unwrap(),
"2a04:4e42:76::159".parse().unwrap(),
"2a04:4e42:77::159".parse().unwrap(),
"2a04:4e42:78::159".parse().unwrap(),
"2a04:4e42:79::159".parse().unwrap(),
"2a04:4e42:7a::159".parse().unwrap(),
"2a04:4e42:7b::159".parse().unwrap(),
"2a04:4e42:7c::159".parse().unwrap(),
"2a04:4e42:7d::159".parse().unwrap(),
"2a04:4e42:7f::159".parse().unwrap(),
"2a04:4e42:8000::159".parse().unwrap(),
"2a04:4e42:80::159".parse().unwrap(),
"2a04:4e42:82::159".parse().unwrap(),
"2a04:4e42:83::159".parse().unwrap(),
"2a04:4e42:84::159".parse().unwrap(),
"2a04:4e42:85::159".parse().unwrap(),
"2a04:4e42:86::159".parse().unwrap(),
"2a04:4e42:87::159".parse().unwrap(),
"2a04:4e42:88::159".parse().unwrap(),
"2a04:4e42:89::159".parse().unwrap(),
"2a04:4e42:8a::159".parse().unwrap(),
"2a04:4e42:8b::159".parse().unwrap(),
"2a04:4e42:8c::159".parse().unwrap(),
"2a04:4e42:8d::159".parse().unwrap(),
"2a04:4e42:8e::159".parse().unwrap(),
"2a04:4e42:8f::159".parse().unwrap(),
"2a04:4e42:9000::159".parse().unwrap(),
"2a04:4e42:9::159".parse().unwrap(),
"2a04:4e42:a000::159".parse().unwrap(),
"2a04:4e42:a::159".parse().unwrap(),
"2a04:4e42:b000::159".parse().unwrap(),
"2a04:4e42:b::159".parse().unwrap(),
"2a04:4e42:c000::159".parse().unwrap(),
"2a04:4e42:c::159".parse().unwrap(),
"2a04:4e42:d::159".parse().unwrap(),
"2a04:4e42:f000::159".parse().unwrap(),
"2a04:4e42:fcf::159".parse().unwrap(),
"2a04:4e42:fd0::159".parse().unwrap(),
"2a04:4e42:fd1::159".parse().unwrap(),
"2a04:4e42:fd2::159".parse().unwrap(),
"2a04:4e42:fd9::159".parse().unwrap(),
"2a04:4e42:fda::159".parse().unwrap(),
"2a04:4e42:fdf::159".parse().unwrap(),
"2a04:4e42:fe4::159".parse().unwrap(),
"2a04:4e42:fe5::159".parse().unwrap(),
"2a04:4e42:fed::159".parse().unwrap(),
"2a04:4e42:ff0::159".parse().unwrap(),
"2a04:4e42:fff::159".parse().unwrap(),
];
let test_url = "https://pbs.twimg.com/media/GhPAiRlaEAA9h4z?format=jpg&name=4096x4096";
let client = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()
.unwrap();
#[derive(Debug, Serialize, Deserialize)]
struct TestResult {
ip: Ipv6Addr,
duration: Duration,
}
#[derive(Debug, Serialize, Deserialize)]
struct ResultJson {
tested_at: SystemTime,
results: Vec<TestResult>,
}
let mut results: Vec<TestResult> = Vec::new();
for ip in ips {
let start = Instant::now();
let res = client
.get(test_url.replace("pbs.twimg.com", &format!("[{}]", &ip.to_string())))
.header(reqwest::header::HOST, "pbs.twimg.com")
.send()
.await;
let duration = start.elapsed();
println!("IP: {}, STATUS: {:?}, TIME: {:?}", ip, res, duration);
results.push(TestResult { ip, duration });
}
results.sort_by(|a, b| a.duration.cmp(&b.duration));
println!("{:#?}", results);
let result_json_name = std::path::Path::new("result.json");
let result_json = serde_json::to_string(&ResultJson {
tested_at: SystemTime::now(),
results,
})
.unwrap();
fs::write(result_json_name, result_json).await.unwrap();
let config = aws_config::load_from_env().await;
let client = aws_sdk_s3::Client::new(&config);
let body = aws_sdk_s3::primitives::ByteStream::from_path(result_json_name)
.await
.unwrap();
client
.put_object()
.bucket(env::var("BUCKET_NAME").unwrap())
.key("twimg/result.json")
.body(body)
.send()
.await
.unwrap();
}