#!/usr/bin/env python
# _*_ Coding:utf-8 _*_
# Author:mazhenkai
#import OS
Import Paramiko
Def cat_ip_host_disk ():
Stdin,stdout,stderr = Ssh.exec_command ("Ifconfig eth0|grep ' inet ' |awk-f ' [:] ' {print $13} '; Hostname;df-ht ',get_pty=True)
Res,err = Stdout.read (), Stderr.read ()
result = ResIf reselse err
Print (Result.decode ())
Def svn_listen ():
Stdin,stdout,stderr = Ssh.exec_command ("Ifconfig eth0|grep ' inet ' |awk-f ' [:] ' {print $13} '; Hostname;df-ht ',get_pty=True)
result = Stdout.read ()
Print (Result.decode ())
Print"\033[32M------Port_listen-----\033[0m]
Stdin,stdout,stderr = Ssh.exec_command (' Netstat-an | grep 80 | grep Listen;netstat-an | grep 443 | grep LISTEN ',get_pty=True)
Res,err = Stdout.read (), Stderr.read ()
result = ResIf reselse err
Print (Result.decode ())
Def ci_port ():
Print"------port_listen-------")
Stdin,stdout,stderr = Ssh.exec_command ("Netstat-lntup | grep 8080 ")
result = Stdout.read ()
Print (Result.decode ())
SSH = Paramiko. Sshclient ()
Ssh.set_missing_host_key_policy (Paramiko. Autoaddpolicy ())
#SVN
Ssh.connect (Hostname=' IP ',Port= Port,Username=' Account name ',password=' Password ')
Svn_listen ()
#CIpub01
Ssh.connect (hostname =port= Port, username= "account Name", password= ' password ')
Cat_ip_host_ Disk ()
Ci_port ()
#CIpub02
Ssh.connect (hostname= IP ", port= port, username= ' account name ', password= ' Password ')
Cat_ip_host_disk ()
Ci_port ()
Ssh.close ()
Implementation effect is as follows
Python3_paramiko Monitoring Server port (case)