python VMware RedHat 实现ssh连接测试

RedHat 5 配置ip,使得你的Windows 能访问虚拟机下的Redhat,可以参考下面地址:

http://www.cnblogs.com/shitouer/archive/2012/05/05/2484771.html


python 代码如下:

#!/usr/bin/env python
import paramiko


#hostname='192.168.0.102'
hostname='192.168.40.5'
username='root'
password='pandason'


#port=22
if __name__=='__main__':
        paramiko.util.log_to_file('paramiko.log')
        s=paramiko.SSHClient()
        #s.load_system_host_keys()
        s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        s.connect(hostname = hostname,username=username, password=password)
        stdin,stdout,stderr=s.exec_command('ifconfig;free;df -h')
        print stdout.read()
        s.close()

运行结果:

D:\Python27\python.exe E:/pythonpc/sshtest.py
eth0      Link encap:Ethernet  HWaddr 00:0C:29:70:8A:39  
          inet addr:192.168.40.5  Bcast:192.168.40.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fe70:8a39/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:225 errors:0 dropped:0 overruns:0 frame:0
          TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:22301 (21.7 KiB)  TX bytes:15142 (14.7 KiB)
          Interrupt:67 Base address:0x2024 


lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:2644 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2644 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:4010152 (3.8 MiB)  TX bytes:4010152 (3.8 MiB)


             total       used       free     shared    buffers     cached
Mem:       1035040     414332     620708          0      32448     284196
-/+ buffers/cache:      97688     937352
Swap:      2096472          0    2096472
文件系统              容量  已用 可用 已用% 挂载点
/dev/hda1              20G  2.6G   16G  14% /
/dev/hda3              18G  173M   17G   2% /home
tmpfs                 506M     0  506M   0% /dev/shm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值