我在 Mobaxterm 中编写脚本来自动登录时遇到问题。Expect 脚本似乎运行得不太好。
#!/usr/bin/expect -f
spawn telnet <IP address>
expect -re "login"
send "username\n"
expect -re "Password"
send "password of the user\n"
interact
Run Code Online (Sandbox Code Playgroud)
场景: 我公司的基础设施要求我通过 ssh 进入跳转服务器,然后才能通过 telnet 进入 cisco 路由器。因此,如果我必须通过 CLI 进行登录,我的登录将如下所示:
ssh xxxx
telnet yyyy
********公司横幅********
NOC:用户名
密码:密码
请帮忙!
我需要创建一个BAT文件来通过telnet运行应用程序,但据我所知,在DOS上无法做到这一点.Telnet不允许在连接的瞬间将任何命令发送到远程机器,并且BAT文件中的每个后续命令仅在telnet停止后执行.这段假设的代码说明了我想要做的事情:
telnet 100.99.98.1 "C:\Application\app.exe -a -b -c"
Run Code Online (Sandbox Code Playgroud)
这将使用三个参数在机器100.99.98.1上运行app.exe.尽管我努力,但没有任何效果.有没有办法做到这一点?
韩国社交协会,
佩德林巴蒂斯塔
我通过telnet连接到硬件设备.就I/O而言,该设备非常简单.所以我向它提交一个命令,之后设备每次一行抽出一行数据,每秒一次.每行只包含一个数字.
所以我的问题是:如果我使用python的telnetlib连接到这个设备,我如何获取一段固定时间(或固定数量的数据行)的数据?
我已经尝试使用所有各种read_命令,但它们似乎都无限期地阻塞,除了read_until,我无法使用,因为输出不能用于确定何时停止.
(我在Cygwin下运行python 2.5,顺便说一句).
编辑:也许真正的问题是,我是否应该使用telnetlib,或者我应该只使用套接字模块?
如何运行Python程序,以便输出STDOUT并将其STDIN输入/输出远程telnet客户端?
所有程序都打印出文本然后重复等待raw_input().我希望远程用户无需shell访问即可使用它.它可以是单线程/单用户.
我试图在Windows XP上通过Telnet访问某些网站,每当我打开一个网站或我的80端口时,它都会回复或者我输入的其他任何目标.127.0.0.1
connecting to 127.0.0.1 ...
经过很长一段时间,连接超时,我什么都没有.
我的浏览器工作正常.
有什么不对?
我试图通过telnet与Windows服务器中的应用程序进行交互,所以我使用的是TelnetClient()方法.我可以使用System.in.read()进行交互(发送命令和检索结果),但是我希望这个程序能够在不使用任何键盘输入的情况下自动运行.所以,我的问题是,为什么System.in.read()工作,但ByteArrayInputStream不工作?
到目前为止这是我的代码:
public class telnetExample2 implements Runnable, TelnetNotificationHandler{
static TelnetClient tc = null;
public static void main (String args[]) throws IOException, InterruptedException{
tc = new TelnetClient();
while (true){
try{
tc.connect("192.168.1.13", 8999);
}
catch (SocketException ex){
Logger.getLogger(telnetExample2.class.getName()).log(Level.SEVERE, null,ex);
}
Thread reader = new Thread(new telnetExample2());
tc.registerNotifHandler(new telnetExample2());
String command = "getversion"; //this is the command i would like to write
OutputStream os = tc.getOutputStream();
InputStream is = new ByteArrayInputStream(command.getBytes("UTF-8")); //i'm using UTF-8 charset encoding here
byte[] buff = new byte[1024];
int …
Run Code Online (Sandbox Code Playgroud) 我需要帮助确定这些ANSI转义序列代表什么.我目前正在编写的终端屏幕阅读器中过滤/评估ANSI代码,但我不确定它们是什么.
转义序列:
[0;1毫米
[0; 1 ;;4米
我使用下面的转义序列图作为参考:http: //ascii-table.com/ansi-escape-sequences-vt-100.php
我不确定这个标题是否具有丰富的信息.
我正在尝试查找/编写一个套接字服务器,它将接受来自客户端(telnet)的连接,然后代表连接的客户端,连接到网络内的四个telnet服务器之一.
连接后,我会计算出有多少连接,然后如果有4个连接,则禁止任何新连接,直到四个连接中的一个可用.
我写了这个:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static int nodeCount = 4;
static int currentNode = 1;
static void Main(string[] args)
{
ServerProgram server = new ServerProgram();
}
class ServerProgram
{
private TcpListener tcpPrimaryListener;
private Thread listenThread;
public ServerProgram()
{
this.tcpPrimaryListener = new TcpListener(IPAddress.Any, 23);
Console.WriteLine("Telnet BBS Port Concentrator Server Started.");
Console.WriteLine("--------------------------------------------");
this.listenThread = new Thread(new ThreadStart(ListenForClients));
this.listenThread.Start();
}
private void …
Run Code Online (Sandbox Code Playgroud) 我被告知通过发送JSON作为请求将图像上传到服务器.
JSON就像下面这样:
{"action":"setMap","data":{"mapName":"myMapName","mapURL":"http://tinypic.com/myimg"}}
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用TELNET来发布JSON.
我想我应该写下面的东西
terminal>telnet my.ip.num.ber port
POST /setMap HTTP/1.1
Run Code Online (Sandbox Code Playgroud)
但不知道如何继续.
我应该写
DATA : {"action":"setMap","data":{"mapName":"myMapName","mapURL":"http://tinypic.com/myimg"}}
Run Code Online (Sandbox Code Playgroud)
我怎样才能收到JSON?
这里有一台只能通过telnet进行控制的特殊设备,我已经做了一段时间了(通过PuTTy或Terminal)。
在NodeJS中,我创建了一个Web界面,可以更轻松地控制设备。我通过为通过telnet发送的不同命令运行不同的bash脚本来做到这一点。这样做很好,但是感觉太杂乱无章,更不用说每个命令的shell脚本了。我正在寻找一种更好的方法。
我想到直接从NodeJS连接到telnet服务器。我尝试了不同的程序包(即net,telnet客户端,telnet流,另一个telnet客户端等),但这不是我需要的那些工具,或者我只是没有正确实现它。
这是我正在使用telnet-client软件包测试的示例代码(其他仅为此示例的变体):
const telnet = require('telnet-client');
const server = new telnet();
// display server response
server.on("data", function(data){
console.log(''+data);
});
// login when connected
server.on("connect", function(){
server.write("login <user> <pass>");
});
// connect to server
server.connect({
host: "172.16.0.1",
port: 9600
});
Run Code Online (Sandbox Code Playgroud)
手动完成后,在“登录”请求之后,我应该看到“登录成功”消息,但是我什么也没回来。
该代码不正确吗?我不熟悉telnet,非常感谢您的帮助。