Giter Site home page Giter Site logo

ssh_jumper's Introduction

๐ŸŒ๐Ÿ’จ SSH Jumper

Crates.io docs.rs CI Coverage Status

Async SSH tunnel through a jump host.

use std::borrow::Cow;
use ssh_jumper::{
    model::{HostAddress, HostSocketParams, JumpHostAuthParams, SshTunnelParams},
    SshJumper
};

// Similar to running:
// ssh -i ~/.ssh/id_rsa -L 1234:target_host:8080 [email protected]
let (local_socket_addr, ssh_forwarder_end_rx) = {
    let jump_host = HostAddress::HostName(Cow::Borrowed("bastion.com"));
    let jump_host_auth_params = JumpHostAuthParams::new(
        Cow::Borrowed("my_user"),
        Cow::Borrowed(Path::new("~/.ssh/id_rsa")),
    );
    let target_socket = HostSocketParams {
        address: HostAddress::HostName(Cow::Borrowed("target_host")),
        port: 8080,
    };
    let ssh_params =
        SshTunnelParams::new(jump_host, jump_host_auth_params, target_socket)
            // Optional: OS will allocate a port if this is left out
            .with_local_port(1234);

    SshJumper::open_tunnel(&ssh_params).await?
};

// Now you can send traffic to `local_socket_addr`, and it will go to `target_host`.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

ssh_jumper's People

Contributors

azriel91 avatar kanashius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ssh_jumper's Issues

Channel open failure (administratively prohibited)

thread 'main' panicked at 'called Result::unwrap() on an Err value: SshTunnelOpenFail(Custom { kind: Other, error: "Channel open failure (administratively prohibited)" })', src\main.rs

     let params = JumpHostAuthParams::password(
            Cow::from("root"),
            Cow::from("Wangfu123"),
        );

     let  add=  match lookup_host("localhost:80").await {
           Ok(mut addrs) => {
               if let Some(addr) = addrs.next() {
                   // Extract the IpAddr from the resolved address
                   let ip_addr = addr.ip();
                   println!("Resolved IP address: {:?}", ip_addr);
                    Some(ip_addr)
               } else {
                   eprintln!("No addresses found for localhost");
                   None

               }
           }
           Err(e) => {
               eprintln!("Failed to resolve address: {:?}", e);
               None
           },
       };

       let  add2=  match lookup_host("sshhost:80").await {
           Ok(mut addrs) => {
               if let Some(addr) = addrs.next() {
                   // Extract the IpAddr from the resolved address
                   let ip_addr = addr.ip();
                   println!("Resolved IP address: {:?}", ip_addr);
                   Some(ip_addr)
               } else {
                   eprintln!("No addresses found for localhost");
                   None
               }
           }
           Err(e) => {

               eprintln!("Failed to resolve address: {:?}", e);
               None
           },
       };
       let target_socket = HostSocketParams {
           address:  HostAddress::IpAddr(add.unwrap()),
           port: 8090,
       };
        let ssh_params = SshTunnelParams::new(HostAddress::IpAddr(add2.unwrap()), params, target_socket)
            // Optional: OS will allocate a port if this is left out
            .with_local_port(8099);
        let (_, r) = SshJumper::open_tunnel(&ssh_params).await.unwrap();

        r.await.expect("");

   

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.