test python TOR proxy and REST-JSON

This commit is contained in:
rootzoll 2020-05-22 20:06:59 +02:00
parent 4a634725af
commit 75b013d96b

View file

@ -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")