forked from ericchou-python/A10_Networks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_information.py
61 lines (48 loc) · 1.81 KB
/
system_information.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
#
# v1, October 31, 2013
# by Eric Chou
#
# Reference: AX_aXAPI_Ref_v2-20121010.pdf
# Usage:
# python system_information.py -d <device> -m <method>
# python system_information.py -d 192.168.148.163 -m "system.time.get"
#
import httplib, json, urllib, urllib2, optparse, time
# specify device and command
parser = optparse.OptionParser()
parser.add_option('-d', '--device', dest="device", action="store")
parser.add_option('-m', '--method', dest="method", action="store")
options, args = parser.parse_args()
device = options.device
method = options.method
# patch httplib.HTTPSConnection.connect
def connect_patched(self):
"Connect to a host on a given (SSL) port."
sock = socket.create_connection((self.host, self.port),self.timeout, self.source_address)
if self._tunnel_host:
self.sock = sock
self._tunnel()
self.sock = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=ssl.PROTOCOL_TLSv1)
httplib.HTTPSConnection.connect = connect_patched
# Gets the session ID to
c = httplib.HTTPSConnection(device)
c.request("GET", "/services/rest/V2/?method=authenticate&username=admin&password=a10&format=json")
response = c.getresponse()
data = json.loads(response.read())
session_id = data['session_id']
print "Session Created. Session ID: " + session_id
# Execution Loop
while True:
print "*" * 10
print "The Time is: ", time.strftime("%H:%M:%S")
# Construct HTTP URL and Post Body
post_body = ""
url = "https://" + device + "/services/rest/V2/?&session_id=" + session_id + "&format=json&method="+method
print "URL Created. URL: " + url + " body: " + post_body
# Making request
req = urllib2.Request(url, post_body)
rsp = urllib2.urlopen(req)
content = rsp.read()
print "Result: " + content
time.sleep(1)