Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jpx40 committed Feb 25, 2024
1 parent 4429fb0 commit cfc017e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
13 changes: 13 additions & 0 deletions central/rsrem/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions central/rsrem/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crossbeam-channel = "0.5.11"
crossbeam-epoch = "0.9.18"
crossbeam-queue = "0.3.11"
curl = "0.4.46"
dns-lookup = "2.0.4"
futures = "0.3.30"
futures-util = "0.3.30"
http = "1.0.0"
Expand Down
36 changes: 26 additions & 10 deletions central/rsrem/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#![allow(dead_code)]
#![allow(unused_variables)]

use dns_lookup::{getaddrinfo, AddrInfoHints, SockType};
use ssh2::{Channel, Session, Sftp, Stream};
use std::borrow;
use std::clone;
use std::fs::File;
use std::io::prelude::*;
Expand All @@ -13,11 +15,11 @@ use std::net::IpAddr;
use std::net::TcpStream;
use std::net::{Ipv4Addr, Ipv6Addr};
use std::path::Path;
use std::result;
use std::str::Bytes;
use std::string::String;
use std::thread::Result;
use std::{path::PathBuf, time::Duration};

#[derive(Debug, Clone)]
struct User {
username: String,
Expand Down Expand Up @@ -48,7 +50,7 @@ impl Connection {
}
}
}
type PingResult = (bool, String);
struct PingResult(bool, String, String);
impl Connection {
fn connect(&self) -> Session {
let tcp = TcpStream::connect(format!("{:?}:{:?}", self.host, self.port)).unwrap();
Expand All @@ -57,27 +59,41 @@ impl Connection {
session.handshake().unwrap();
session
}
fn ping(&self) -> PingResult {
fn ping(&self) -> (bool, String, Option<IpAddr>) {
let mut ip: String = String::new();
let mut status: bool;
let mut r: (bool, String) = (false, String::new());
let mut r: (bool, String, Option<IpAddr>) = (false, String::new(), None);
match &self.host {
Some(i) => {
ip = i.to_string();
let check = ipaddress::IPAddress::is_valid(i.to_string());
if !check {
let host = self.host.clone().unwrap();
let result = dns_lookup::lookup_host(&host);
match result {
Ok(i) => ip = i[0].to_string(),
Err(_) => {
panic!("No IP address found")
}
};
} else {
ip = i.to_string();
}

status = true;
}
_ => status = false,
}
if status != true {
if !status {
match &self.ipv4 {
Some(i) => {
ip = i.to_string();

status = true;
}
_ => status = false,
}
}
if status != true {
if !status {
match &self.ipv6 {
Some(i) => {
ip = i.to_string();
Expand All @@ -86,7 +102,7 @@ impl Connection {
_ => status = false,
}
}
if status == true {
if status {
let options = ping_rs::PingOptions {
ttl: 128,
dont_fragment: true,
Expand All @@ -101,10 +117,10 @@ impl Connection {
let timeout = Duration::from_secs(1);
//let ip_addr = ipaddress::IPAddress::s
let _ = ping_rs::send_ping(&ip_addr, timeout, &[1, 2, 3, 4], Some(&options));
r = (true, "success".to_string());
r = (true, "success".to_string(), Some(ip_addr));
} else {
let s: String = "No IP address found".to_string();
r = (false, s);
r = (false, s, None);
}
r
}
Expand Down

0 comments on commit cfc017e

Please sign in to comment.