導航:首頁 > 源碼編譯 > 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管理系統源碼相關的資料

熱點內容
新日經銷商用什麼app 瀏覽:351
應用如何加密oppor9 瀏覽:97
oppoa8加密咋關 瀏覽:747
雲伺服器如何拉出來 瀏覽:167
pdf轉換成rtf 瀏覽:804
usb轉網口linux 瀏覽:685
領克車定位app是什麼 瀏覽:819
怎樣給桌面創建新的文件夾 瀏覽:68
江西樂平dns伺服器雲伺服器 瀏覽:622
雲伺服器裡面是自動開啟的嗎 瀏覽:294
3d計算機圖形學pdf 瀏覽:851
怎麼將文件夾內文件名導入excel 瀏覽:307
安卓手機游戲進度怎麼保存 瀏覽:873
伺服電機控制演算法 瀏覽:195
上班族的解壓家居產品設計 瀏覽:470
php遍歷圖片文件 瀏覽:933
聯想a380t刷機包需要解壓嗎 瀏覽:239
linux啟動命令窗口 瀏覽:325
單片機串列通信畢業設計 瀏覽:80
移動app哪裡可以改套餐 瀏覽:337