在某些情况下,我需要远程登录到设备并显示其配置。
如果要逐步手动执行此操作,则以下为详细信息:
version: '3' services: serving: build: . image: testing-models container_name: tf command: --model_config_file=/config/config.conf
正在尝试10.105.234.56 ...已连接到10.105.234.56。转义符 是'^]'。
S524DF4K15000002登录:
telnet 10.105.234.56
密码:欢迎使用!
S524DF4K15000002#
admin
S524DF4K15000002(dns)#
config system dns
配置系统DNS 设置名称“ 8.8.8.8”结尾
S524DF4K15000002(dns)#
其中show
部分是我的输入。
通过此Java代码,
grey
我能够:
public static void main(String[] args){
try{
String command = "config system dns";
String command2 = "show";
String host = "10.105.234.56";
String user = "admin";
String password = "";
JSch jsch = new JSch();
Session session = jsch.getSession(user, host, 22);
Properties config = new Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);;
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream input = channel.getInputStream();
channel.connect();
System.out.println("Channel connected to machine " + host + " server with command: " + command );
try{
InputStreamReader inputReader = new InputStreamReader(input);
BufferedReader bufferedReader = new BufferedReader(inputReader);
String line = null;
while((line = bufferedReader.readLine()) != null){
System.out.println(line);
}
bufferedReader.close();
inputReader.close();
}catch(IOException ex){
ex.printStackTrace();
}
channel.disconnect();
session.disconnect();
}catch(Exception ex){
ex.printStackTrace();
}
但是我可以在此Java代码的何处添加此后续1. telnet 10.105.234.56" with user as: "admin"
2. run "config system dns" command.
命令?
此设备的操作系统有点简单,我无法将两个命令都通过管道传输到一起运行。