diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-23 16:48:28 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-04-11 11:08:01 +0000 |
commit | 108f4375b82537e6e137458af0a0100a0e7f2346 (patch) | |
tree | a60273fbfc57d7325872b6fd5c8c8c5045896ff6 /utils/python-rpc/console.py | |
parent | functional_tests: add more blockchain related tests (diff) | |
download | monero-108f4375b82537e6e137458af0a0100a0e7f2346.tar.xz |
console.py: support connecting to any host, not just 127.0.0.1
Diffstat (limited to '')
-rwxr-xr-x | utils/python-rpc/console.py | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/utils/python-rpc/console.py b/utils/python-rpc/console.py index ab0d9f27f..444a9cc59 100755 --- a/utils/python-rpc/console.py +++ b/utils/python-rpc/console.py @@ -4,27 +4,45 @@ from __future__ import print_function import sys import subprocess import socket +import urlparse from framework import rpc from framework import wallet from framework import daemon -USAGE = 'usage: python -i console.py <port>' +scheme='http' +host='127.0.0.1' +port=None + +USAGE = 'usage: python -i console.py [[scheme]<host>:]<port>' try: - port = int(sys.argv[1]) -except: + try: + port = int(sys.argv[1]) + except: + t = urlparse.urlparse(sys.argv[1], allow_fragments = False) + scheme = t.scheme or scheme + host = t.hostname or host + port = t.port or port + if scheme != 'http' and scheme != 'https': + print(USAGE) + sys.exit(1) + if port <= 0 or port > 65535: + print(USAGE) + sys.exit(1) +except Exception, e: + print('Error: ' + str(e)) print(USAGE) sys.exit(1) # check for open port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(1) -if s.connect_ex(('127.0.0.1', port)) != 0: +if s.connect_ex((host, port)) != 0: print('No wallet or daemon RPC on port ' + str(port)) sys.exit(1) s.close() # both wallet and daemon have a get_version JSON RPC -rpc = rpc.JSONRPC('{protocol}://{host}:{port}'.format(protocol='http', host='127.0.0.1', port=port)) +rpc = rpc.JSONRPC('{protocol}://{host}:{port}'.format(protocol=scheme, host=host, port=port)) get_version = { 'method': 'get_version', 'jsonrpc': '2.0', |