python通过ssh和shell交互

import paramiko
 
#创建一个ssh的客户端
ssh = paramiko.SSHClient()
#创建一个ssh的白名单
know_host = paramiko.AutoAddPolicy()
#加载创建的白名单
ssh.set_missing_host_key_policy(know_host)
#连接服务器
ssh.connect(
    hostname = "192.168.1.1",
    port = 1288,
    username = "altfactory",
    password = "pPRodU6c17!0nN"
)
 
shell = ssh.invoke_shell()
shell.settimeout(1)
 
command = input(">>>"+"\n")
shell.send(command)
while True:
    try:
        recv = shell.recv(512).decode()
        if recv:
            print(recv)
        else:
            continue
    except:
        command = input(">>>") + "\n"
        shell.send(command)
ssh.close() #关闭连接
Warning (from warnings module):
  File "D:\program\python39\lib\site-packages\paramiko\transport.py", line 236
    "class": algorithms.Blowfish,
CryptographyDeprecationWarning: Blowfish has been deprecated
>>>
sys led on
[9292] Jan 01 02:01:52 lastlog_perform_login: Couldn't stat /var/log/lastlog: No such file or directory

[9292] Jan 01 02:01:52 lastlog_openseek: /var/log/lastlog is not a file or directory!

[9292] Jan 01 02:01:52 wtmp_write: problem writing /var/log/wtmp: No such file or directory

(root)>
sys led on
>>>sys led off
sys led off


Usage: sys led [on||off] 



(root)>
>>>serialization --show
serialization --show


sap=

product_id=

altice_sn=

manufacturer_sn=

date=190001??-0000

equip_id=

hw_version=

bom=

sw_version=

cid=0x0

rf_filter=0

mac=22:c3:00:50:01:21

gpon_sn=

gpon_pw=

wifi_pw=

bosa_sn=

bosa_pn=

bosa_type=

bosa_vapd=0

bosa_ith=0

bosa_imod=0

bosa_impd=0

bosa_refpwr=0

bosa_tiavcc=0

bosa_apd_resp=0

bosa_apd_comp=0

bosa_apd_max_i=0

darkcurrent_vapd10=-1

darkcurrent_vop=-1

pin_resp=-1

rf_oma=-1

rf_out_target=-1

target_er_set=-1


(root)>
>>>sys led off
sys led off


All led is turned off! 



(root)>
>>>

你可能感兴趣的:(python,ssh,linux,运维)