Home
Sign Up
Sign In
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member
Sign In
推荐学习书目
›
Learn Python the Hard Way
Python Sites
›
PyPI
- Python Package Index
›
http://diveintopython.org/toc/index.html
›
Pocoo
值得关注的项目
›
PyPy
›
Celery
›
Jinja2
›
Read the Docs
›
gevent
›
pyenv
›
virtualenv
›
Stackless Python
›
Beautiful Soup
›
结巴中文分词
›
Green Unicorn
›
Sentry
›
Shovel
›
Pyflakes
›
pytest
Python 编程
›
pep8 Checker
Styles
›
PEP 8
›
Google Python Style Guide
›
Code Style from The Hitchhiker's Guide
V2EX
›
Python
通过 Paramiko 的 SSH 连接执行命令的结果如何实时输出?
todayzhou
·
Feb 21, 2018
· 13436 views
This topic created in 2993 days ago, the information mentioned may be changed or developed.
import paramiko
trans = paramiko.Transport(('x.x.x.x', 22))
trans.connect(username='root', password='123123')
ssh = paramiko.SSHClient()
ssh._transport = trans
stdin, stdout, stderr = ssh.exec_command('tcpdump -i any -nne -c 10')
print(stdout.read().decode())
ssh.close()
这里打印出 stdout 的时候已经是命令执行的所有结果,如何每收到一次数据就打印出来,比如我执行的 tcpdump 命令,我想实现每捕获到一个报文就实时的显示出来,而不是等抓了 10 个以后再一起显示。
paramiko
ssh
stdout
nne
7 replies
•
2018-09-09 22:37:50 +08:00
1
ysc3839
Feb 22, 2018 via Android
https://stackoverflow.com/questions/25260088/paramiko-with-continuous-stdout
2
dandogn
Feb 22, 2018
用消息通道,提示你:invoke_shell()
3
todayzhou
OP
Feb 22, 2018
@
ysc3839
谢谢,昨天我也自己看到了,测试了可以。
4
todayzhou
OP
Feb 22, 2018
@
dandogn
谢谢你,invoke_shell 和我需要的还是有点区别。多谢!
5
fanne
Sep 5, 2018
@
todayzhou
#4 大佬,这个问题你后来怎么解决了,我目前也遇到此问题,试了 stackoverflow 里的,貌似也不行
6
fanne
Sep 5, 2018
@
todayzhou
#3 顺序错了,现在可以了
7
fanne
Sep 9, 2018
@
todayzhou
#3 hello,你的中文怎么处理的?
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
2507 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 38ms ·
UTC 06:48
·
PVG 14:48
·
LAX 23:48
·
JFK 02:48
♥ Do have faith in what you're doing.
❯