大家帮我看看这段JB下连接交换机的程序有什么错误。

erupt 2005-05-14 10:20:41
//在JB下Telnet连接交换机
public void checkport()
{
try{
if (connect("192.168.253.3", 23) == 1) {
int error;
String sendW = new String();

error = waits("assword:");
if (error < 1) {
this.jTextArea1.append("交换机连接出错");
}
sendW = "cisco";//密码
for (int i = 0; i < sendW.length(); i++) {
output.write(sendW.charAt(i));
output.flush();
}

if (error < 1) {
this.jTextArea1.append("交换机连接出错");
}
error = waits(">");
if (error < 1) {
this.jTextArea1.append("交换机连接出错");
}
sendW = "en";//输入enable,交换机下要求的命令
for (int i = 0; i < sendW.length(); i++) {
output.write(sendW.charAt(i));
output.flush();
}

if (error < 1) {
this.jTextArea1.append("交换机连接出错");
}
error = waits("assword:");

if (error < 1) {
this.jTextArea1.append("交换机连接出错");
}
sendW = "cisco";//再次输入密码
for (int i = 0; i < sendW.length(); i++) {
output.write(sendW.charAt(i));
output.flush();
}
error = waits("#");

if (error < 1) {
this.jTextArea1.append("交换机连接出错");
}
sendW = "sh interfaces status";//输入交换机命令
for (int i = 0; i < sendW.length(); i++) {
output.write(sendW.charAt(i));
output.flush();
}


} else
this.jTextArea1.append("交换机不可达");
}catch(IOException e)
{this.jTextArea1.append(e.toString());}
}

//connect the switch
public int connect(String swName,int port)
{
int k=1;
try{
sk=new Socket(swName,port);
input=new TelnetInputStream(sk.getInputStream(),true);
output=new TelnetOutputStream(sk.getOutputStream(),true);
}catch(IOException e){k=-1;}
return k;
}

public int timeout = 50000;//等待延迟
//等待交换机响应
public int waits(String prompt)
{

String tmp = "";
String tmpmess=tmp;
int nt=1;
do {
try { tmp = new String(receive()); }
catch(Exception e) { this.jTextArea1.append(e.toString());return -1; }
nt=nt+1;
if (nt>timeout){return 0; }
if (tmp.length()>0)
{
tmpmess=tmp;
}
} while(tmp.indexOf(prompt) == -1);
this.jTextArea1.append(tmpmess);
return 1;
}
//接受来自交换机的信息
public byte[] receive() throws IOException {
int count = input.available();

byte buf[] = new byte[count];
count = input.read(buf);
String x=new String(buf);
return buf;
}



输出结果:User Access Verification



Password: 交换机连接出错交换机连接出错交换机连接出错交换机连接出错

好像是inputstream不太对。交换机接受不到密码。所以出错的。可是我找不到错误在哪里,能否帮我看看。谢谢了!
...全文
40 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
erupt 2005-05-31
  • 打赏
  • 举报
回复
我已经解决了。可是没有办法结帖。随便来个人顶一下。我要散分了
miaoliujun 2005-05-31
  • 打赏
  • 举报
回复
给分吧

你顺便说下解决的方法
erupt 2005-05-14
  • 打赏
  • 举报
回复
顺便问一下,大家有没有telnet服务器或者交换机的源码,能否发给我一份。十分感谢!erupt918@163.com

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧