关于javaethz翻页的信息
本篇文章给大家谈谈javaethz翻页,以及对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java ssh登陆交换机执行命令
- 2、Java通过SSH获取Linux文件出错
- 3、我用java远程连接linux报错了,可以互相ping得通,网络没问题。
- 4、java SSH远程到linux 执行本地的脚本
- 5、如何用java远程登录windows
java ssh登陆交换机执行命令
第一步下载java扩展包
第二步:解压文件把 jar包,拷贝到java的库目录下,我的是ubuntu14(/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext )
cp ganymed-ssh2-build210.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext
第三步: 把默认账户修改成直接的账户密码
yang@yang:~/Downloads/java/ganymed-ssh2-build210/examples$ cat Basic.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class Basic
{
public static void main(String[] args)
{
String hostname = "127.0.0.1";
String username = "user";
String password = "password";
try
{
Connection conn = new Connection(hostname);
conn.connect();
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new IOException("Authentication failed.");
Session sess = conn.openSession();
sess.execCommand("uname -a date uptime who");
System.out.println("Here is some information about the remote host:");
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while (true)
{
String line = br.readLine();
if (line == null)
break;
System.out.println(line);
}
System.out.println("ExitCode: " + sess.getExitStatus());
sess.close();
conn.close();
}
catch (IOException e)
{
e.printStackTrace(System.err);
System.exit(2);
}
}
}
第四步: 编译 javac Basic.java java Basic
Here is some information about the remote host:
Linux yang 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
2014年 05月 03日 星期六 17:26:00 CST
17:26:00 up 6:09, 4 users, load average: 0.15, 0.21, 0.23
yang :0 2014-05-03 11:17 (:0)
yang pts/2 2014-05-03 16:34 (:0)
yang pts/26 2014-05-03 17:13 (:0)
yang pts/27 2014-05-03 17:24 (:0)
ExitCode: 0
Java通过SSH获取Linux文件出错
1
ssh
在cygwin中执行:$
ssh
username@remotehost
2
scp
命令scp基于ssh协议,可以将本地文件拷贝到远程服务上的指定目录
我用java远程连接linux报错了,可以互相ping得通,网络没问题。
根据情况有2种原因,:
1、网络问题,ping命令走的icmp协议,测试网络端口的连通性是错误的,请使用telnet命令来测试目的主机的的ssh端口是否有效;
2、ssh的server端配置问题,请查看ssh是否允许密码登录,还是更安全的秘钥文件登录。
java SSH远程到linux 执行本地的脚本
scp file yonghuming@服务器 :/路径
把本地文件 file 传送到 服务器 的 /路径 下。
然后就可以远程执行了。
如何用java远程登录windows
Java使用SSH远程访问Windows并执行命令
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class SSHWindows {
public static void main(String[] args) {
// TODO Auto-generated method stub
String hostname ="192.168.30.10";
String username="administrator";
String password="Talent123";
try{
//建立连接
Connection conn= new Connection(hostname);
// System.out.println("set up connections");
conn.connect();
//利用用户名和密码进行授权
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if(isAuthenticated ==false)
{
// System.out.println("--------");
throw new IOException("Authorication failed");
}
//打开会话
Session sess = conn.openSession();
// System.out.println("cmd----");
//执行命令
sess.execCommand("ruby C:\\WhatWeb-master\\whatweb --output-xml ");
// System.out.println("The execute command output is:");
InputStream stdout = new StreamGobbler(sess.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
while(true)
{
String line = br.readLine();
if(line==null) break;
System.out.println(line);
}
// System.out.println("Exit code "+sess.getExitStatus());
sess.close();
conn.close();
// System.out.println("Connection closed");
}catch(IOException e)
{
System.out.println("can not access the remote machine");
}
}
}
javaethz翻页的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、javaethz翻页的信息别忘了在本站进行查找喔。