-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshellssh.py
More file actions
executable file
·64 lines (51 loc) · 2.16 KB
/
shellssh.py
File metadata and controls
executable file
·64 lines (51 loc) · 2.16 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
# see LICENSE file (it's GPL)
#usage send ip or mac to recive the device ip or mac, send cmd:any_comande to be excuted
import subprocess
import time
from pygsm import GsmModem
class CountLettersApp(object):
def __init__(self, modem):
self.modem = modem
def incoming(self, msg):
######################### execution camnde
if msg.text=="ip":
p=subprocess.Popen("ifconfig eth0 | grep 'inet addr:' | cut -d: -f2 | awk '{print $1}'",shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
else:
if msg.text=="mac":
p=subprocess.Popen("ifconfig eth0 | grep 'HWaddr'",shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
else:
if msg.text=="remotemac":
p=subprocess.Popen("ssh abdelbar@192.168.0.120 ifconfig eth1 | grep 'HWaddr'",shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
else:
if msg.text.startswith('cmd:'):
p = subprocess.Popen(msg.text[4:], shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
else:
p=p=subprocess.Popen("",shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
######################## envoi de repons
o,stderr = p.communicate()
status = p.poll()
print "mesage a envoyer :" + o
var=raw_input("envoyer ce mesage ? y/n")
if var=="y":
msg.respond("comande unswer:" + o)
else:
print "no"
def serve_forever(self):
while True:
print "Checking for message..."
msg = self.modem.next_message()
if msg is not None:
print "Got Message: %r ------ %s" % (msg,msg.text)
self.incoming(msg)
time.sleep(2)
# all arguments to GsmModem.__init__ are optional, and passed straight
# along to pySerial. for many devices, this will be enough:
Daisy13_on_D6="/dev/ttyS1"
gsm = GsmModem(port=Daisy13_on_D6,baudrate=115200,logger=GsmModem.debug_logger).boot()
print "Waiting for network..."
s = gsm.wait_for_network()
# start the demo app
app = CountLettersApp(gsm)
app.serve_forever()