aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRustDesk <[email protected]>2022-09-20 06:02:30 +0800
committerGitHub <[email protected]>2022-09-20 06:02:30 +0800
commit85af668a4f746a8138cbc0d26e2eba66ab95cfa0 (patch)
treed071a5db7744f56af2b6f964cb4ff3848b5566c5
parent74cb82c8a205fc459750b84e1ef3678d5d905316 (diff)
parentbf3e9471a6710ca19da2eff38f5cb35151edf787 (diff)
downloadrustdesk-server-85af668a4f746a8138cbc0d26e2eba66ab95cfa0.tar.gz
rustdesk-server-85af668a4f746a8138cbc0d26e2eba66ab95cfa0.zip
Merge pull request #88 from paspo/doctor
rustdesk-server doctor
-rw-r--r--Cargo.toml2
-rw-r--r--src/utils.rs88
2 files changed, 86 insertions, 4 deletions
diff --git a/Cargo.toml b/Cargo.toml
index d652980..8d51a11 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -49,6 +49,8 @@ http = "0.2"
flexi_logger = { version = "0.22", features = ["async", "use_chrono_for_offset"] }
ipnetwork = "0.20"
local-ip-address = "0.4"
+dns-lookup = "1.0.8"
+ping = "0.4.0"
[build-dependencies]
hbb_common = { path = "libs/hbb_common" }
diff --git a/src/utils.rs b/src/utils.rs
index 7eb7a58..7b36aed 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -1,8 +1,11 @@
+use dns_lookup::{lookup_addr, lookup_host};
use hbb_common::{bail, ResultType};
use sodiumoxide::crypto::sign;
-use std::env;
-use std::process;
-use std::str;
+use std::{
+ env,
+ net::{IpAddr, TcpStream},
+ process, str,
+};
fn print_help() {
println!(
@@ -10,7 +13,8 @@ fn print_help() {
rustdesk-util [command]\n
Available Commands:
genkeypair Generate a new keypair
- validatekeypair [public key] [secret key] Validate an existing keypair"
+ validatekeypair [public key] [secret key] Validate an existing keypair
+ doctor [rustdesk-server] Check for server connection problems"
);
process::exit(0x0001);
}
@@ -68,6 +72,76 @@ fn validate_keypair(pk: &str, sk: &str) -> ResultType<()> {
Ok(())
}
+fn doctor_tcp(address: std::net::IpAddr, port: &str, desc: &str) {
+ let start = std::time::Instant::now();
+ let conn = format!("{}:{}", address, port);
+ if let Ok(_stream) = TcpStream::connect(conn.as_str()) {
+ let elapsed = std::time::Instant::now().duration_since(start);
+ println!(
+ "TCP Port {} ({}): OK in {} ms",
+ port,
+ desc,
+ elapsed.as_millis()
+ );
+ } else {
+ println!("TCP Port {} ({}): ERROR", port, desc);
+ }
+}
+
+fn doctor_ip(server_ip_address: std::net::IpAddr, server_address: Option<&str>) {
+ println!("\nChecking IP address: {}", server_ip_address);
+ println!("Is IPV4: {}", server_ip_address.is_ipv4());
+ println!("Is IPV6: {}", server_ip_address.is_ipv6());
+
+ // reverse dns lookup
+ // TODO: (check) doesn't seem to do reverse lookup on OSX...
+ let reverse = lookup_addr(&server_ip_address).unwrap();
+ if server_address.is_some() {
+ if reverse == server_address.unwrap() {
+ println!("Reverse DNS lookup: '{}' MATCHES server address", reverse);
+ } else {
+ println!(
+ "Reverse DNS lookup: '{}' DOESN'T MATCH server address '{}'",
+ reverse,
+ server_address.unwrap()
+ );
+ }
+ }
+
+ // TODO: ICMP ping?
+
+ // port check TCP (UDP is hard to check)
+ doctor_tcp(server_ip_address, "21114", "API");
+ doctor_tcp(server_ip_address, "21115", "hbbs extra port for nat test");
+ doctor_tcp(server_ip_address, "21116", "hbbs");
+ doctor_tcp(server_ip_address, "21117", "hbbr tcp");
+ doctor_tcp(server_ip_address, "21118", "hbbs websocket");
+ doctor_tcp(server_ip_address, "21119", "hbbr websocket");
+
+ // TODO: key check
+}
+
+fn doctor(server_address_unclean: &str) {
+ let server_address3 = server_address_unclean.trim();
+ let server_address2 = server_address3.to_lowercase();
+ let server_address = server_address2.as_str();
+ println!("Checking server: {}\n", server_address);
+ let server_ipaddr = server_address.parse::<IpAddr>();
+ if server_ipaddr.is_err() {
+ // the passed string is not an ip address
+ let ips: Vec<std::net::IpAddr> = lookup_host(server_address).unwrap();
+ println!("Found {} IP addresses: ", ips.iter().count());
+
+ ips.iter().for_each(|ip| println!(" - {ip}"));
+
+ ips.iter().for_each(|ip| doctor_ip(*ip, Some(server_address)));
+
+ } else {
+ // user requested an ip address
+ doctor_ip(server_ipaddr.unwrap(), None);
+ }
+}
+
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() <= 1 {
@@ -88,6 +162,12 @@ fn main() {
}
println!("Key pair is VALID");
}
+ "doctor" => {
+ if args.len() <= 2 {
+ error_then_help("You must supply the rustdesk-server address");
+ }
+ doctor(args[2].as_str());
+ }
_ => print_help(),
}
}