From bc70ff7a3d88efc0586c4d1dd9812a6bbef6ebdf Mon Sep 17 00:00:00 2001 From: TomasGl Date: Wed, 21 Jul 2021 22:50:39 +0300 Subject: [PATCH] Add I2PControl.py --- I2PControl.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 I2PControl.py diff --git a/I2PControl.py b/I2PControl.py new file mode 100644 index 0000000..a0d60ad --- /dev/null +++ b/I2PControl.py @@ -0,0 +1,23 @@ +from requests import post +from json import dumps + + +class I2PControl: + headers = {'content-type': 'application/json'} + + def __init__(self, ip): + self.host = 'https://{}:7650'.format(ip) + + def auth(self, password): + data = {'id': 0, 'jsonrpc': '2.0', 'method': 'Authenticate', 'params': {'API': 2, 'Password': password}} + self.token = post(self.host, data=dumps(data), headers=self.headers, verify=False).json()['result']['Token'] + + def request(self, method, params): + data = {'id': 0, 'jsonrpc': '2.0', 'method': method, 'params': params | {'Token': self.token}} + # required python 3.9 + return post(self.host, data=dumps(data), headers=self.headers, verify=False).json()['result'] + + +control = I2PControl('127.0.0.1') +control.auth('itoopie') +assert control.request('Echo', {'Echo': 'echo string'})['Result'] == 'echo string'