Write a batch ping host script using Python

Source: Internet
Author: User

Write a script to ping the host in bulk by using Python to verify that the host is active

#!/usr/bin/python#auther: jacky#date: 2016-08-01#filename: ping_ip.pyimport os,sysimport  subprocess,cmddef subping ():     f = open ("Ip_list.txt", "R")      lines = f.readlines ()     for line in lines:         line=line.strip (' \ n ')          ret = subprocess.call ("ping -c 2 -w 5 %s"  % line, Shell=true,stdout=subprocess. PIPE)         if ret == 0:             str =  '%s is alive '  % line             print str         elif ret == 1:            str =  '%s is not alive '  % line             print str    f.close () subping ()

Host list file name Ip_list.txt

192.168.56.12192.168.56.13192.168.56.14


This article is from "Jacky Xin" blog, please be sure to keep this source http://jackyxin.blog.51cto.com/1976631/1834196

Write a batch ping host script using Python

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.