daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jan 20th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. # Unsorted
  3. from multiprocessing import Pool
  4. import os
  5.  
  6. def ping(ip):
  7.   global results
  8.   report = ("No response","Partial Response","Alive")
  9.   pingaling = os.popen("ping -q -c2 "+str(ip),"r")
  10.   while 1:
  11.     line = pingaling.readline()
  12.     try:
  13.       result = line[line.find(','):].split()[1]
  14.       output = report[int(result[0])]
  15.     except:
  16.       pass
  17.     if not line: break
  18.   print "Testing %s : %s!" % (ip, output)
  19.  
  20. if __name__ == '__main__':
  21.   pool = Pool(processes=10)
  22.   host = ['81.24.212.'+str(x) for x in range(10)]
  23.   pool.map(ping, host, 1)
  24.   pool.close()
  25.   pool.join()
  26.  
  27.  
  28. ----------------------------------------------------------------------------------------------
  29.  
  30. #!/usr/bin/env python
  31. # Sorted
  32. from multiprocessing import Pool
  33. import os
  34.  
  35. def ping(ip):
  36.   global results
  37.   report = ("No response","Partial Response","Alive")
  38.   pingaling = os.popen("ping -q -c2 "+str(ip),"r")
  39.   while 1:
  40.     line = pingaling.readline()
  41.     try:
  42.       result = line[line.find(','):].split()[1]
  43.       output = report[int(result[0])]
  44.     except:
  45.       pass
  46.     if not line: break
  47.   return "Testing %s : %s!" % (ip, output)
  48.  
  49. if __name__ == '__main__':
  50.   pool = Pool(processes=10)
  51.   host = ['81.24.212.'+str(x) for x in range(10)]
  52.   unsorted = pool.map(ping, host, 1)
  53.   pool.close()
  54.   pool.join()
  55.   for line in sorted(unsorted):
  56.       print line
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top