miguelcl

ApiRest Sys connections python

Nov 17th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.62 KB | None | 0 0
  1. import re
  2. import subprocess
  3.  
  4. p1 = subprocess.Popen([
  5.         'curl',
  6.         '-sk',
  7.         '-u',
  8.         'admin:admin',
  9.         '-H','Content-Type: application/json',
  10.         '-H','Accept: application/json',
  11.         '-X','GET',
  12.         'https://x.x.x.x/mgmt/tm/sys/connection'
  13. ],stdout=subprocess.PIPE)
  14.  
  15.  
  16. p2 = subprocess.Popen([
  17.         'perl',
  18.         '-pe',
  19.         '\'s/\\n/,\n/g\''
  20. ],stdin=p1.stdout,stdout=subprocess.PIPE)
  21.  
  22.  
  23. result = str(p2.communicate()).split('\\n')
  24.  
  25. for line in result:
  26.         if re.search('^[0-9].*', line) is not None:
  27.                 ip = line.split(" ")
  28.                 print ip[0]
Advertisement
Add Comment
Please, Sign In to add comment