-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeerinf.py
28 lines (25 loc) · 938 Bytes
/
peerinf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Copyright (c) 2020 Vishnu J. Seesahai
# Use of this source code is governed by an MIT
# license that can be found in the LICENSE file.
import subprocess
import os, sys, json
#from resource import *
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath('.'), relative_path)
def get_inf(uname, pwd):
try:
cmd = "bin/pktctl -u "+ uname +" -P "+ pwd +" getpeerinfo"
result, err = subprocess.Popen(resource_path(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
#print('Result:', result)
result = json.loads(result.decode('utf-8'))
err = err.decode('utf-8')
if err:
print('Error:', err)
result = {}
return result
except Exception as e:
print('Exception:', e)
result = {}
return result