| 1 | #!/usr/bin/python |
|---|
| 2 | |
|---|
| 3 | import urllib2, base64 |
|---|
| 4 | import simplejson |
|---|
| 5 | |
|---|
| 6 | url = 'http://localhost/auth/run.cgi/wordlist?corpname=bnc;wlattr=word;wlminfreq=5;wlmaxitems=100;wlpat=test.*;format=json' |
|---|
| 7 | |
|---|
| 8 | usr = '<username>' |
|---|
| 9 | passwd = '<password>' |
|---|
| 10 | |
|---|
| 11 | request = urllib2.Request(url) |
|---|
| 12 | |
|---|
| 13 | # authentication |
|---|
| 14 | base64string = base64.encodestring('%s:%s' % (usr, passwd))[:-1] |
|---|
| 15 | request.add_header("Authorization", "Basic %s" % base64string) |
|---|
| 16 | |
|---|
| 17 | # json data receiving |
|---|
| 18 | file = urllib2.urlopen(request) |
|---|
| 19 | data = file.read() |
|---|
| 20 | file.close() |
|---|
| 21 | |
|---|
| 22 | # now, in the 'data' variable, there is a json string that can be parsed |
|---|
| 23 | # for json syntax (e.g. by simplejson) |
|---|
| 24 | |
|---|
| 25 | json_obj = simplejson.loads(data) |
|---|
| 26 | print simplejson.dumps(json_obj, sort_keys=True, indent=3) |
|---|