no_vpn/
lib.rs

1//! Translate is the first VPN checking crate in rust
2//!
3//! Requirements:
4//! - An internet connection
5//! - OpenSSL
6//!
7//! Warning:
8//! - This crate use reqwest
9//!
10//! Functionnalities:
11//! - Check if an ip is a VPN
12//! - Get the country of an ip
13//!
14//! Examples:
15//! ```
16//! use no_vpn::*;
17//! check_vpn("IP",|result| {
18//! 	let result = result.unwrap();
19//!		println!("VPN: {}, Country: {}",result.is_vpn(),result.get_country());
20//! })
21//! ```
22//! Specials thank's to besuper who has autorized me to convert the popular NoVPN minecraft plugin written in java to a Rust API
23//! https://www.spigotmc.org/resources/novpn-antibot-bungeecord-support-mcleaks.36511/ If you want to buy the minecraft plugin
24
25extern crate crypto;
26extern crate chrono;
27extern crate reqwest;
28extern crate base16;
29
30use crypto::sha2::{Sha256};
31use crypto::digest::Digest;
32use chrono::{Datelike, Utc};
33type z = String;
34
35#[cfg(test)]
36mod tests {
37	use crate::*;
38    #[test]
39    fn ip_test() {
40		f("91.168.123.129".b(),|ie| {
41			assert_eq!(ie.unwrap().is_vpn(),false);
42		});
43		std::thread::sleep(std::time::Duration::from_millis(5000));
44    }
45}
46/// This structure represent a VPN checker result
47#[derive(Debug)]
48pub struct VpnResult {
49	a: z,
50	b: bool
51}
52
53impl VpnResult {
54
55	pub fn is_vpn(&self) -> bool {
56		self.b
57	}
58
59	pub fn get_country(&self) -> String {
60		self.a.b()
61	}
62}
63
64trait y {
65	fn a(&self,a: &str,b: &str) -> String;
66	fn b(&self) -> String;
67	fn c(&self,a: &str) -> bool;
68}
69
70impl y for String {
71	fn a(&self,a: &str,b: &str) -> String {
72		self.replace(a,b)
73	}
74	fn b(&self) -> String {
75		self.to_string()
76	}
77	fn c(&self,a: &str) -> bool {
78		self.contains(a)
79	}
80}
81
82impl y for &str {
83	fn a(&self,a: &str,b: &str) -> String {
84		self.replace(a,b)
85	}
86	fn b(&self) -> String {
87		self.to_string()
88	}
89	fn c(&self,a: &str) -> bool {
90		self.contains(a)
91	}
92}
93
94/// This function check if an ip has an VPN
95/// You can use the following example:
96/// ```
97/// no_vpn::check_vpn("IP",|result| {
98/// 	let result = result.unwrap();
99///		println!("VPN: {}, Country: {}",result.is_vpn(),result.get_country());
100/// })
101/// ```
102pub fn check_vpn<Q>(ip: &str,end: Q)
103    where
104        Q: Send + 'static + FnOnce(Option<VpnResult>) {
105    f(ip.b(),end);
106}
107
108fn g(s: z,a: z,b: z) -> z {
109	let mut c = z::with_capacity(s.len());
110	for d in s.chars() { 
111	    c.insert(0,d);
112	}
113	z::from_utf8(base16::decode(&c).unwrap()).unwrap().a("$1",&a).a("$2",&b).b()
114}
115
116fn f<Q>(a: z,b: Q)
117    where
118        Q: Send + 'static + FnOnce(Option<VpnResult>) {
119    std::thread::spawn(move || {
120    	b(
121    	match reqwest::Client::new().get(&g("2342f256d616e627563757f21342f2960716f293830383a3330313e2238313e2433323e29383f2f2a307474786".to_string(),a.to_string(),d()))
122      		.send() {
123            Ok(mut e) => {
124                let c: z = match e.text() {
125                	Ok(e) => {
126                		e.b()
127                	},
128                	_ => {
129                		"".b()
130                	}
131                };
132                if c.c("N;") || c.c("Y;") {
133                	let v: Vec<&str> = c.split(";").collect();
134                	Some(VpnResult{a: v[1].b(),b: v[0].b() == "Y".b()})
135                } else {
136                	None
137                }
138            },
139            _ => {
140            	None
141            }
142        });
143    });
144}
145
146fn d() -> z {
147    let d = Utc::now();
148    let (_b, e) = d.year_ce();
149	let c = format!("{}{}{}",d.day(),crate::b(),e);
150	let a: &str = &format!("{}{}",c,g("83565737c463532337179516a615f3b637a646370716d4".b(),"".b(),"".b()));
151	let mut b = Sha256::new();
152	b.input_str(a);
153	b.result_str().b()
154}
155
156fn b() -> z {
157	match Utc::now().month() {
158		1 => {
159			"January"
160		},
161		2 => {
162			"February"
163		},
164		3 => {
165			"March"
166		},
167		4 => {
168			"April"
169		},
170		5 => {
171			"May"
172		},
173		6 => {
174			"June"
175		},
176		7 => {
177			"July"
178		},
179		8 => {
180			"August"
181		},
182		9 => {
183			"September"
184		},
185		10 => {
186			"October"
187		},
188		11 => {
189			"November"
190		},
191		12 => {
192			"December"
193		},
194		_ => {
195			"Error"
196		}
197	}.b()
198}