Advertisement
Guest User

pritunl_api_test

a guest
Jan 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import requests, time, uuid, hmac, hashlib, base64
  4.  
  5. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  6. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  7.  
  8. BASE_URL = 'https://localhost'
  9. API_TOKEN = 'AW4TdnfVfCqbPk67wfWNGUCNc3U9YAkZ'
  10. API_SECRET = 'ps3ovQeKrqHKrHPpfQdsuYqjHr3ehtJG'
  11. method = 'get'
  12. path = '/organization'
  13.  
  14. auth_timestamp = str(int(time.time()))
  15. auth_nonce = uuid.uuid4().hex
  16. auth_string = '&'.join([API_TOKEN, auth_timestamp, auth_nonce, method.upper(), path])
  17.  
  18. # auth_signature = base64.b64encode(hmac.new(
  19. #        API_SECRET, auth_string, hashlib.sha256).digest())
  20.  
  21. # auth_signature = base64.b64encode(hmac.new(API_SECRET, auth_string, hashlib.sha256).digest())
  22. # auth_signature = base64.b64encode(hmac.new(API_SECRET.encode('utf-8'), auth_string.encode('utf-8'), hashlib.sha256).digest())
  23.  
  24. # hmacv = hmac.new(str.encode(API_SECRET), auth_string.encode('utf-8'), hashlib.sha256).digest()
  25. # auth_signature = base64.b64encode(hmacv)
  26.  
  27. auth_headers = {
  28.         'Auth-Token': API_TOKEN,
  29.         'Auth-Timestamp': auth_timestamp,
  30.         'Auth-Nonce': auth_nonce,
  31.         'Auth-Signature': auth_signature
  32.     }
  33. print('auth headers: ' + str(auth_headers))
  34.  
  35. r = requests.get(BASE_URL + path, verify=False)
  36. r.headers = auth_headers
  37. print(r.status_code)
  38.  
  39. try:
  40.   print(r.content)
  41. except:
  42.   print('no content')
  43.   pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement