导航:首页 > 源码编译 > javassh管理系统源码

javassh管理系统源码

发布时间:2024-09-13 10:13:36

A. 怎么用java实现ssh协议通信

importch.ethz.ssh2.Connection;
importch.ethz.ssh2.Session;
importch.ethz.ssh2.StreamGobbler;
importcom.io.Debug;
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStream;
importjava.io.InputStreamReader;
importjava.io.OutputStream;
/**
*
*@authorleon.lee
*/
{
privateStringusername="";
privateStringoldpassword="";
privateConnectionconn=;
privatebooleanhasError=false;
privateStringErrorMessage="";
privatebooleanisSuccessfully=false;
privateStringSystemMessage="";

publicstaticfinalStringHOST="127.0.0.1";//serverip
publicbooleanisSuccessfully(){
returnisSuccessfully;
}
publicbooleanisHasError(){
returnhasError;
}
publicStringgetErrorMessage(){
returnErrorMessage;
}
publicvoidsetErrorMessage(Stringmsg){
hasError=true;
this.ErrorMessage=msg;
}
/**
*Createsanewinstanceof<code>ChangeEmailPassword</code>.
*@paramusername
*@paramoldpassword
*/
publicChangeEmailPassword(Stringusername,Stringoldpassword){
this.username=username;
this.oldpassword=oldpassword;
try{
conn=newConnection(HOST);
conn.connect();
/*Authenticate*/
booleanisAuthenticated=conn.authenticateWithPassword(username,oldpassword);
if(isAuthenticated==false){
setErrorMessage("Authenticationfailed.");
conn=;
}
}catch(Exceptione){
conn.close();
conn=;
System.out.println(e);
}
}
publicvoidsetNewPassword(Stringnewpassword){
if(hasError){
return;
}
if(conn==){
return;
}
try{
Sessionsess=conn.openSession();
sess.execCommand("passwd");
InputStreamso=sess.getStdout();
InputStreamerr=sess.getStderr();
OutputStreamout=sess.getStdin();

byte[]buffer=newbyte[500];//其实没有必要这么大.130就差不多了.怕万一有什么提示.
intlength=0;
length=err.read(buffer);
//if(length>0){
//System.out.println("#1:"+newString(buffer,0,length));
////(current)UNIXpassword:
//}
Stringcoldpassword=oldpassword+" ";
out.write(coldpassword.getBytes());
length=err.read(buffer);
//if(length>0){
//System.out.println("#2:"+newString(buffer,0,length));
////(current)UNIXpassword:
//}
Stringcnewpass=newpassword+" ";
out.write(cnewpass.getBytes());
length=err.read(buffer);
if(length>0){
Stringrs=newString(buffer,0,length);
//System.out.println("#3:"+rs);
if(rs.indexOf("BAD")>-1){
sess.close();
conn.close();
setErrorMessage(rs);
return;
}
}
out.write(cnewpass.getBytes());
length=so.read(buffer);
if(length>0){
Stringrs=newString(buffer,0,length);
if(rs.indexOf("successfully")>-1){
this.isSuccessfully=true;
this.SystemMessage=rs;
}
}
/*Closethissession*/
sess.close();
/*Closetheconnection*/
conn.close();
}catch(IOExceptione){
e.printStackTrace(System.err);
}
}
/**
*@
*/
publicstaticvoidmain(String[]args){
ChangeEmailPasswordcep=newChangeEmailPassword("username","oldpassword");
if(cep.isHasError()){
System.out.println(cep.getErrorMessage());
cep=;
return;
}
cep.setNewPassword("newpassword");
if(cep.isHasError()){
System.out.println(cep.getErrorMessage());
cep=;
return;
}
if(cep.isSuccessfully){
System.out.println(cep.getSystemMessage());
}
}
/**
*@returntheSystemMessage
*/
publicStringgetSystemMessage(){
returnSystemMessage;
}
}

B. java ssh椤圭洰锛岀粡杩囦竴涓猘ction锛屾庝箞鑳借烦杞鍒扮栌搴﹂栭〉锻锛燂纻锛燂纻

action閲宺eturn "" 铹跺悗鍦ㄩ厤缃鏂囦欢<result name="" type="redirect">锏惧害缃戝潃</result>

阅读全文

与javassh管理系统源码相关的资料

热点内容
不要惹飙车的程序员 浏览:811
怎么解压成lmf3格式 浏览:310
云服务器设置端口转发 浏览:585
数学分析复旦pdf 浏览:280
用什么能改打印服务器 浏览:145
上海不动产权证怎么加密码 浏览:587
linux推荐版本 浏览:574
安卓网格布局有什么特点 浏览:327
生化危机用什么app看 浏览:916
布谷鸟搜索算法matlab 浏览:138
服务器的灯如何设置 浏览:862
单片机控制门流程图 浏览:304
沪漂女程序员跳槽 浏览:306
百度石榴算法指的是 浏览:786
怎么将文件压缩得尽可能小 浏览:447
linux开发常用命令 浏览:831
我的世界java版如何进入服务器 浏览:897
如何把jpg转换pdf格式 浏览:290
华为p10plus图片加密 浏览:369
宏杰文件夹加密密码忘了 浏览:620