projects
/
remote-debug.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rename file and add readme
[remote-debug.git]
/
suanzi-support
diff --git
a/suanzi-support
b/suanzi-support
index
41ed9fc
..
367f379
100755
(executable)
--- a/
suanzi-support
+++ b/
suanzi-support
@@
-1,29
+1,27
@@
#!/usr/bin/env python2
#!/usr/bin/env python2
-# dependencies:
-# 1. pip install paho-mqtt
-# 2. apt-get install sshpass
-#
from subprocess import call, Popen, PIPE, STDOUT
import paho.mqtt.client as mqtt
import shlex
from subprocess import call, Popen, PIPE, STDOUT
import paho.mqtt.client as mqtt
import shlex
-import os
import random
from uuid import getnode as get_mac
MQTT_SERVER = 'mqtt.suanzi.ai'
MQTT_PORT = 1883
import random
from uuid import getnode as get_mac
MQTT_SERVER = 'mqtt.suanzi.ai'
MQTT_PORT = 1883
+
+# The alive time new ssh session exist. It means if no client connect to this device through ssh tunnel in 5 minutes,
+# this new sessin will terminate.
ALIVE_TIME = 60 * 5
SSH_SERVER = 'autossh.suanzi.ai'
ALIVE_TIME = 60 * 5
SSH_SERVER = 'autossh.suanzi.ai'
-PORT_RANGE = (20000,
3
0000)
+PORT_RANGE = (20000,
4
0000)
USER = 'autossh'
PASSWORD = 'hard2guess'
def getAvailablePort(host, ports):
while True:
port = random.randint(ports[0], ports[1])
USER = 'autossh'
PASSWORD = 'hard2guess'
def getAvailablePort(host, ports):
while True:
port = random.randint(ports[0], ports[1])
- command = 'nc -z -v -w
5
' + host + ' ' + str(port)
+ command = 'nc -z -v -w
3
' + host + ' ' + str(port)
p = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
pout = p.communicate()[0].strip()
if p.returncode == 0:
p = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
pout = p.communicate()[0].strip()
if p.returncode == 0:
@@
-36,14
+34,12
@@
def getAvailablePort(host, ports):
def exec_ssh(port):
if port == None:
raise Exception('Port not avaliable')
def exec_ssh(port):
if port == None:
raise Exception('Port not avaliable')
- #command = 'sshpass -p' + PASSWORD + ' ssh -o "ServerAliveInterval 30" -o "ServerAliveCountMax 1" -fCNR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER
- command = 'sshpass -p' + PASSWORD + ' ssh -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -fCR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER + ' sleep ' + str(ALIVE_TIME)
+ command = 'sshpass -p' + PASSWORD + ' ssh -o "StrictHostKeyChecking=no" -o "UserKnownHostsFile /dev/null" -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -fCR ' + str(port) +':localhost:22 ' + USER + '@' + SSH_SERVER + ' sleep ' + str(ALIVE_TIME)
print command
return call(shlex.split(command), shell=False)
def on_connect(client, userdata, flags, rc):
print command
return call(shlex.split(command), shell=False)
def on_connect(client, userdata, flags, rc):
- #client.subscribe("rpdzkj-request")
client.subscribe(client.id + '-request')
print("Connected with result code "+str(rc))
client.subscribe(client.id + '-request')
print("Connected with result code "+str(rc))
@@
-66,7
+62,7
@@
class MyClient(mqtt.Client):
if __name__ == '__main__':
mac = hex(get_mac())
if __name__ == '__main__':
mac = hex(get_mac())
- id =
os.getenv('USER') + '-' + '{:0>12}'.format(mac[2:13
])
+ id =
'{:0>12}'.format(mac[2:-1
])
print 'id is: ' , id
client = MyClient(id)
client.connect(MQTT_SERVER, MQTT_PORT, 60)
print 'id is: ' , id
client = MyClient(id)
client.connect(MQTT_SERVER, MQTT_PORT, 60)