Advertisement
BinaryJacob

Request params

Feb 12th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. import csv
  2. import json
  3. import requests
  4. import re
  5. from datetime import datetime
  6. from requests.auth import HTTPBasciAuth
  7.  
  8.  
  9. url = 'http://localhost/api/v2/hosts'
  10.  
  11. r = requests.get(url, auth=HTTPBasicAuth('admin', password))
  12.  
  13. data = str(r.json())
  14.  
  15. rst=re.compile(r'[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}', re.U)
  16.  
  17. current_time=datetime.now()
  18. date_format=current_time("%Y-%m-%d %H:%M:%S")
  19.  
  20. namefile="%s.csv" %(date_format)
  21.  
  22.  
  23. with open(namefile, "a") as fl:
  24.         data=csv.writer(fl, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
  25.         data.writerow(["IP"])
  26.         for row in rst.findall(data):
  27.                 print(row)
  28.                 data.writerow([row])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement