mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-25 07:07:46 +01:00
test python TOR proxy and REST-JSON
This commit is contained in:
parent
4a634725af
commit
75b013d96b
1 changed files with 22 additions and 4 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
import sys
|
||||
import locale
|
||||
import requests
|
||||
import json
|
||||
from dialog import Dialog
|
||||
|
||||
# display config script info
|
||||
|
@ -22,10 +24,26 @@ if sys.argv[1] == "menu":
|
|||
d = Dialog(dialog="dialog",autowidgetsize=True)
|
||||
d.set_background_title("IP2TOR Subscription Service")
|
||||
code, tag = d.menu("OK, then you have two options:",
|
||||
choices=[("(1)", "Leave this fascinating example"),
|
||||
("(2)", "Leave this fascinating example")])
|
||||
choices=[("(1)", "Test HTTP REQUEST thru TOR PROXY"),
|
||||
("(2)", "Make REST API - JSON request")])
|
||||
if code == d.OK:
|
||||
print("OK --> ")
|
||||
print(tag)
|
||||
if tag == "(1)":
|
||||
session = requests.session()
|
||||
session.proxies = {'http': 'socks5://127.0.0.1:9050', 'https': 'socks5://127.0.0.1:9050'}
|
||||
print("Needs: pip3 install pysocks\n")
|
||||
print("Call 'http://httpbin.org/ip' thru TOR proxy:\n")
|
||||
print(session.get("http://httpbin.org/ip").text)
|
||||
print("Call 'http://httpbin.org/ip' normal:\n")
|
||||
print(requests.get("http://httpbin.org/ip").text)
|
||||
print("Call 'https://shop.ip2t.org/api/v1/public/hosts/' thru TOR:\n")
|
||||
print(session.get("https://shop.ip2t.org/api/v1/public/hosts/").text)
|
||||
if tag == "(2)":
|
||||
myresp = requests.get('https://shop.ip2t.org/api/v1/public/hosts/')
|
||||
jData = json.loads(myresp.content)
|
||||
print("The response contains {0} properties".format(len(jData)))
|
||||
print("\n")
|
||||
for key in jData:
|
||||
print (key)
|
||||
print("\n")
|
||||
else:
|
||||
print("Cancel")
|
Loading…
Add table
Reference in a new issue