你敢来帮小弟我回答上嘛你敢来帮小弟我回答上嘛
你敢来帮我回答下嘛~
public class SSHmain
{
public static void main(String[] args)
{
String hostname = 192.168.1.1 ;//要登陆目标主机
String username = lbb ;//登陆用的用户名
String password = cisco ; //登陆用到的密码
try
{
/* Create a connection instance */
Connection conn ...
你敢来帮小弟我回答上嘛
你敢来帮我回答下嘛~
public class SSHmain
{
public static void main(String[] args)
{
String hostname = 192.168.1.1 ;//要登陆目标主机
String username = lbb ;//登陆用的用户名
String password = cisco ; //登陆用到的密码
try
{
/* Create a connection instance */
Connection conn = new Connection(hostname);
/* Now connect */
conn.connect();
/* Authenticate */
boolean isAuthenticated = conn.authenticateWithPassword(username, password);
if (isAuthenticated == false)
throw new
IOException( Authentication failed. );
/* Create a session */
Session sess = conn.openSession();
//sess.execCommand( uname -a date uptime who );
sess.execCommand( show );
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);
}
/* Show exit status, if available (otherwise null ) */
System.out.println( ExitCode: + sess.getExitStatus());
/* Close this session */
sess.close();
/* Close the connection */
conn.close();
}
catch (IOException e)
{
e.printStackTrace(
System.err);
System.exit(2);
}
}
}
怎么才能执行多条命令,为什么我调用第二个execCommand()方法总是决绝连接,我想用
这个远程登入到交换机
------最佳解决
--------------------------------------------------------
我敢,但是,这个我真不会啊
------其他解决方案--------------------------------------------------------
引用:
我敢,但是,这个我真不会啊
-0 -我搞不定啊,为什么不能执行多条,大神你有其他ssh登入的方法吗
------其他解决方案--------------------------------------------------------
用个SSH软件登陆、不用自己手写
------其他解决方案--------------------------------------------------------
引用:
本文档为【你敢来帮小弟我回答上嘛】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。