远程登录自动化/脚本 [英] Telnet automation / scripting

查看:152
本文介绍了远程登录自动化/脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经检查该课题但找不到什么我在找。我运行Windows(客户端),服务器是一个遗留的主机类型的服务器。

I have already checked This Question but could not find what i'm looking for. I am running Windows (the client), and the server is a legacy mainframe type server.

基本上我需要写一个脚本,蟒蛇code或什么的,把一些通过telnet知道服务器的命令,preferable捕获输出。然后,完成后返回。

Basically I need to write a script, python code or whatever, to send some know commands to the server via telnet, and preferable capture the output. Then return when done.

什么是最好的方法呢?

推荐答案

有对远程登录连接的 Python库读取和写入自/至telnet连接。

There's a python library for telnet connections that reads and writes from/to a telnet connection.

检查链接。它有你在找什么一些基本的例子。

Check the link. It has some basic examples of what you are looking for.

下面是从链接的例子:

import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter your remote account: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")

tn.write("ls\n")
tn.write("exit\n")

print tn.read_all()

它连接到Telnet服务器。发送您的登录凭据,然后执行unix命令 LS 。然后退出了会议,并打印从Telnet服务器所有输出。

It connects to a telnet server. Sends your login credentials and then executes the unix command ls. Then exits the session and prints all output from the telnet server.

这篇关于远程登录自动化/脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆