Python3_paramiko Monitoring Server port (case)

Source: Internet
Author: User
Tags stdin

#!/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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.