UrbanPro
true

Learn Python Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Python SubProcess

Logeswaran
07/09/2017 0 0
Question: As a Network Administrator, one of my trainee wants to know the below:
He has certain number of Machines(IP’s). On daily basic he wants to know how many IP’s are reachable and how many are not.
By using python Subprocess library we can attain this:
 
Sample script:
import subprocess
# Generate the list of IP address to verify the reachability
a=["10.126.172.170","10.126.172.88","1.1.1.1","10.126.172.89"]
result = {}
for i in a:
     print("====== PING Status of %s ======="%i)
     process = subprocess.Popen
          ('ping %s'%i,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE )
     output=process.communicate()[0]
     print (output)
     if '(100% loss)' in output:
           result[i]='Not reachable'
     elif '(0% loss)' in output:
           result[i]='Reachable' print ("======== FINAL RESULT =============\n") print(result) print("\n=========================================")
 
Above Program Screenshot:
 
 
Output of the above Program:
 
 
0 Dislike
Follow 2

Please Enter a comment

Submit

Other Lessons for You

Python programming - Applications
If you’re thinking of learning Python? Or if you recently started learning it? You may be asking yourself: "What exactly can I use Python for?" There are so many applications for python, but there...

A Python Program to calculate Variance and Standard Deviation
Finding the variance and the standard deviation. Variance and Standard Deviation are related measures of dispersion that tell us more about a list of numbers,like are they...

map function in python
The function map takes a function and an iterable as arguments and returns a new iterable with the function applied to each argument. Example: def add_five(x): return x+5 nums = result = list(map(add_five,...

Code: Gantt Chart: Horizontal bar using matplotlib for tasks with Start Time and End Time
import pandas as pd from datetime import datetimeimport matplotlib.dates as datesimport matplotlib.pyplot as plt def gantt_chart(df_phase): # Now convert them to matplotlib's internal format... ...
R

Rishi B.

0 0
0

PEP (Python Enhancement Proposals)
Python Enhancement Proposals(PEP) are suggestions for improvements to the language, made by experienced Python developers. PEP 8 is a style guide on the subject of writing readable code. It contains a...
X

Looking for Python Training Classes?

The best tutors for Python Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Python Training with the Best Tutors

The best Tutors for Python Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more