Beispiel #1
0
def get_radio_info():
    client = Client()
    client.connect(host, port)

    print("Sending request to server...")
    # object variables as dict
    client.send(iradio_structs.station_info_request().__dict__)
    radio_list = client.recv()
    print("radio_list recieved")

    return jsonify(**radio_list)
Beispiel #2
0
class Auth(object):
    """Stores Customer password in safe form. I expect only 1 user/admin per script"""

    data = {}  # stores previous data from master

    def __init__(self):
        self.password = None
        try:
            self.client = Client().connect("127.0.0.1", ADMIN_PORT)
        except socket.error:
            self.client = None

    def __ask_master(self):
        req = {
            "method": "get",
            "endpoint": "info"
        }
        if self.client:
            try:
                return self.client.send(req).recv()
            except socket.error:
                return {"error": "Socket f****d up"}
        else:
            return {"error": "No connection"}

    def ask_master(self):
        self.data = self.__ask_master()
        return self.data

    def hash_data(self, data):
        new_hash = hashlib.md5()
        new_hash.update("mask-{0}-vladimir".format(data))
        return new_hash.hexdigest()

    def set_password(self, psw):
        self.password = self.hash_data(psw)

    def check(self, psw):
        return self.password == self.hash_data(psw)

    def password_is_set(self):
        return self.password is not None
Beispiel #3
0
# then from a cli, send the commmand via 'python sendit.py <mode> <HASH> <label>' where hash is the hash on the torrent client,
# label is the label given to the hash on the client, and mode is either add or queue.

from jsonsocket import Client
import sys

host = 'localhost'
port = 50007
mode = sys.argv[1]
if mode == 'queue':
    hash = None
    label = None
else:
    hash = sys.argv[2]
    label = sys.argv[3]

data = {
    'mode': mode,
    'apikey': '#put apikeyhere',
    'hash': hash,
    'label': label
}

client = Client()
client.connect(host, port)
client.send(data)
response = client.recv()
print response
client.close()

Beispiel #4
0
            response = ser.readline()
            print response
        if response.find('PI_SHU') != -1:
            print "sent command"
            client = Client()
            client.connect(host, port).send({'command': 1})
            client.close()
        if response.find('Battery') != -1:
            volt = response[9:-7]

        ser.write('time\n\r')
        response = ser.readline()
        while response.find('$') == -1:
            response = ser.readline()
            print response
        if response.find('PI_SHU') != -1:
            print "sent command"
            client = Client()
            client.connect(host, port).send({'command': 1})
            client.close()
        if response.find('Uptime') != -1:
            timeard = response[8:-9]
            client = Client()
            client.connect(host, port)
            client.send({'command': 3, 'value': volt, 'time': timeard})
            client.close()

except KeyboardInterrupt:
    client.close()
    ser.close()
Beispiel #5
0
#!/usr/bin/python           # This is client.py file

from jsonsocket import Client

host = '192.168.12.1' 	   
port = 7878                # Reserve a port for your service.
client = Client()
print 'Client starts.'

client.connect((host, port))
print 'Client connected.'

client.send({'tx_id': 1234, 'amount': 4321})
response = client.recv()
print response
client.close()
Beispiel #6
0
#!/usr/bin/python           # This is client.py file

from jsonsocket import Client

host = '192.168.12.1'
port = 7878  # Reserve a port for your service.
client = Client()
print 'Client starts.'

client.connect((host, port))
print 'Client connected.'

client.send({'tx_id': 1234, 'amount': 4321})
response = client.recv()
print response
client.close()