How Python judges and peer-to-peer Linux hosts are network-pass

Source: Internet
Author: User
Tags python script

We often use a Python script to log on to the remote Linux system through the Paramiko to perform some script operations, but if the remote host a lot, here we should be able to determine whether the local and remote network is a pass, through a way to determine whether the network is a pass.

1 #!/user/bin/python2 Importsubprocess3 defPing (IP):4cmd ='ping-n 1%s'%IP5outfile ='ping.tmp'6ret = Subprocess.call (cmd,shell=ture,stdout = open (outfile,'A +'), stderr =subprocess. STOUT)7     ifRET = =0:8         Print "%s server is Alive"%IP9     ElseTen         Print "%s Server is down"%IP One  A if '__name__'=='__main__' -Ping (192.1.1.1)

How Python judges and peer-to-peer Linux hosts are network-pass

Related Article

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.