def __init__(self, address, port, file_path, file_name): threading.Thread.__init__(self) self.address = address self.port = port self.client = Client(self.address, self.port) self.file_path = file_path self.file_name = file_name
def sendFile(name, host, port): print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() file_to_send = read_file() client.put("fileToSend.txt", file_to_send) client.disconnect()
def RFCOMM_Sendfile(address, fname="test.txt", fdata=b'Hello world\n'): print("Searching for OBEX service on %s" % address) # Use the server named "OBEX Object Push" to send file service_matches = bluetooth.find_service(name="OBEX Object Push", address=address) if len(service_matches) == 0: print("Couldn't find the service") sys.exit(0) match = service_matches[0] name = match["name"] host = match["host"] port = match["port"] print("Service Name: %s" % match["name"]) print(" Host: %s" % match["host"]) print(" Description: %s" % match["description"]) print(" Provided By: %s" % match["provider"]) print(" Protocol: %s" % match["protocol"]) print(" channel/PSM: %s" % match["port"]) print(" svc classes: %s " % match["service-classes"]) print(" profiles: %s " % match["profiles"]) print(" service id: %s " % match["service-id"]) print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() # The parameter [file_data] must be bytes type like [b'****'],otherwise there will be some error occur in Python3 client.put(name=fname, file_data=fdata) client.disconnect() return
def send_file(self, filename: str, device: str, port: int = None, data=None, service_name='OBEX Object Push', binary: bool = False): """ Send a local file to a device that exposes an OBEX Object Push service :param filename: Path of the file to be sent :param data: Alternatively to a file on disk you can send raw (string or binary) content :param device: Device address or name :param port: Port number :param service_name: Service name :param binary: Set to true if data is a base64-encoded binary string """ from PyOBEX.client import Client if not data: filename = os.path.abspath(os.path.expanduser(filename)) with open(filename, 'r') as f: data = f.read() filename = os.path.basename(filename) else: if binary: data = base64.decodebytes(data.encode() if isinstance(data, str) else data) addr, port, protocol = self._get_addr_port_protocol(device=device, port=port, service_name=service_name) client = Client(addr, port) self.logger.info('Connecting to device {}'.format(addr)) client.connect() self.logger.info('Sending file {} to device {}'.format(filename, addr)) client.put(filename, data) self.logger.info('File {} sent to device {}'.format(filename, addr)) client.disconnect()
def send_text_file(bd_addr, port, filename): res = bytes("my name is Safwan Mansuri", 'utf-8') client = Client(bd_addr, port) client.connect() print('\n') print("Waiting for acceptance......") client.put(filename, res) client.disconnect()
def connect(self): self.refresh() print('Sr.\tAddress \t\tName') for i in range(len(self.nearby_devices)): print( f'{i + 1}.\t{self.nearby_devices[i][0]}\t{self.nearby_devices[i][1]}' ) addr = self.nearby_devices[int( input( '\nEnter the number of the device, to which you wish to connect : ' )) - 1][0] service = find_service(name=b'OBEX Object Push\x00', address=addr)[0] logging.info( f'Connecting to {service["host"]} on port {service["port"]}...') self.client = Client(service["host"], service["port"]) self.client.connect() logging.info('Connection success.')
def send_music(bd_addr, port, filename): Image = open(filename, "rb") data = Image.read() client = Client(bd_addr, port) client.connect() print('\n') print("Waiting for acceptance......") client.put(filename, data) client.disconnect()
class BT: def __init__(self, duration=8): self.duration = duration self.nearby_devices = discover_devices(duration=self.duration, lookup_names=True) self.client = None def refresh(self): logging.info('Please wait, upddating the list of nearby devices...') self.nearby_devices = discover_devices(duration=self.duration, lookup_names=True) def get_nearby_devices(self): return self.nearby_devices def connect(self): self.refresh() print('Sr.\tAddress \t\tName') for i in range(len(self.nearby_devices)): print( f'{i + 1}.\t{self.nearby_devices[i][0]}\t{self.nearby_devices[i][1]}' ) addr = self.nearby_devices[int( input( '\nEnter the number of the device, to which you wish to connect : ' )) - 1][0] service = find_service(name=b'OBEX Object Push\x00', address=addr)[0] logging.info( f'Connecting to {service["host"]} on port {service["port"]}...') self.client = Client(service["host"], service["port"]) self.client.connect() logging.info('Connection success.') def disconnect(self): logging.info(f'Disconnecting from : {self.client.address}...') self.client.disconnect() self.client = None logging.info('Disconnected successfully.') def send_file(self, file_name, binary_data=None): self.connect() logging.info('Sending the file now...') if binary_data is None: with open(file_name, 'rb') as f: contents = f.read() self.client.put(file_name, contents) else: self.client.put(file_name, binary_data) logging.info('File has been sent successfully.') self.disconnect()
def blue_send(device, files=[]): service_matches = find_service(name=b'OBEX Object Push\x00', address=device) first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] client = Client(host, port) client.connect() for file in files: file_content = open(file, 'rb').readlines() if type(file_content) == list: file_content = b''.join(file_content).strip() client.put('Output\\' + file, file_content) client.disconnect()
def bluetooth(target_name, file_name): file_contents = read_file(file_name) if file_contents == "": return 0 target_address = None nearby_devices = bt.discover_devices() for bdaddr in nearby_devices: if target_name == bt.lookup_name(bdaddr): target_address = bdaddr break if target_address is not None: print("Found device with MAC Address: " + target_address) else: print("Couldn't find device") return 0 services = bt.find_service(address=target_address, name=b'OBEX Object Push\x00') if len(services) == 0: print("Couldn't find service") return 0 first_match = services[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] client = Client(host, port) client.connect() client.put(file_name, file_contents) client.disconnect() return 1
class FTPclient(threading.Thread): def __init__(self, address, port, file_path, file_name): threading.Thread.__init__(self) self.address = address self.port = port self.client = Client(self.address, self.port) self.file_path = file_path self.file_name = file_name def run(self): try: self.client.connect() self.client.put(self.file_name, open(self.file_path).read()) print '********************************************************************' print self.address + ' : File Transfer Success!!!' print '********************************************************************' except: print '********************************************************************' print self.address + + ' : File Transfer Failed...' print '********************************************************************' self.client.disconnect() self.client.delete
import bluetooth, os, sys from xml.etree import ElementTree from PyOBEX import client, responses from PyOBEX.client import Client if __name__ == "__main__": device_addr = sys.argv[1] path = sys.argv[2] services = bluetooth.find_service(uuid="0000112f", address=device_addr) if services: port = services[0]["port"] names = services[0]["name"] print("Connecting to port %s with %s" % (port, names)) c = Client(device_addr, port) response = c.connect() pieces = path.split("/") for piece in pieces: print(piece) response = c.setpath(piece) sys.stdout.write("Enteres directory %s \n" % path) response = c.listdir() if isinstance(responce, responses.FailureResponse): sys.stderr.write('Failed to enter directory\n') sys.exit(1) headers, data = response tree = ElementTree.formstring(data) for element in tree.findall("file"): name = element.attrib["name"]
#np.savetxt('intercep.csv', np.array(model.intercept_), delimiter=',') print "Loading parameters" y=np.loadtxt('coef.csv', delimiter =',') z=np.loadtxt('intercep.csv', delimiter =',') print "Loaded" while True: x = input("Enter to start") B1_rand, B2_rand, B3_rand, B4_rand = data_sample() op_e=[] op=[] a=[0 for i in range(16)] for j in range(min([B1_rand.shape[0], B2_rand.shape[0], B3_rand.shape[0], B4_rand.shape[0] ])): formulae(float(B1_rand[j]),float(B2_rand[j]),float(B3_rand[j]),float(B4_rand[j])) b=op.index(max(op)) a[b]+=1 count=(a.index(max(a)))+1 address = '40:83:DE:A4:18:20' svc = bluetooth.find_service(address=address, uuid='1105') first_match = svc[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() client.put("test.txt", str(count)) client.disconnect()
if len(service_matches) == 0: print "Couldn't find any appropriate services" sys.exit(1) # list out all matched services # let user select from the list for i in range(0, len(service_matches)): print"{}) {}".format(i, service_matches[i]) service_match_index = int(raw_input("Select a service: ")) service = service_matches[service_match_index] port = service["port"] server_address = service["host"] name = service["name"] # connect to server print "Connecting to {} ({})".format(name, server_address) client = Client(server_address, port) client.connect() # send some file print "Sending a file..." f = open("c:/users/vpxbo/desktop/test_image.jpg", 'rb') client.put("test.jpg", f.read()) # disconnect from server print "Disconnecting..." client.disconnect() print "Done"
from bluetooth import * from PyOBEX.client import Client import sys addr = sys.argv[1] print("Searching for OBEX service on %s" % addr) service_matches = find_service(name=b'OBEX Object Push\x00', address=addr) if len(service_matches) == 0: print("Couldn't find the service.") sys.exit(0) first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() client.put("test.txt", "Hello world\n") client.disconnect()
for device in devices: print("Sending to %s..." % device) service_matches = bluetooth.find_service(name=b'OBEX Object Push', address=devices[device]) print(service_matches) if len(service_matches) == 0: print("[W] %s not found, not sent." % device) notSent.append(device) else: first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() client.put(filename, dataToSend) client.disconnect() print("Successfuly sent to %s." % device) for x in range(15): if len(notSent) == 0: break else: updatedList = [] for device in notSent: print("Sending to %s..." % device) service_matches = bluetooth.find_service(name=b'OBEX Object Push', address=devices[device]) print(service_matches)
from bluetooth import * from PyOBEX.client import Client import sys addr = '48:9D:24:CA:16:86' port = 3 #print("Searching for OBEX service on %s" % addr) #service_matches = find_service(name=b'OBEX Object Push\x00', address = addr ) #if len(service_matches) == 0: # print("Couldn't find the service.") # sys.exit(0) #first_match = service_matches[0] #port = first_match["port"] #name = first_match["name"] #host = first_match["host"] #print("Connecting to \"%s\" on %s" % (name, host)) client = Client(addr, port) client.connect() client.put("/home/pr0xy/export/pyscripts/test-bt.py", "Hello world\n") client.disconnect()
import bluetooth from PyOBEX.client import Client import sys address = "80:6C:1B:F0:FA:7B" uuid = "8ce255c0-200a-11e0-ac64-0800200c9a66" print("Searching for OBEX service on %s" % address) #service_matches = bluetooth.find_service(name='OBEX Object Push', address = address ) service_matches = bluetooth.find_service(uuid=uuid, address=address) if len(service_matches) == 0: print("Couldn't find the service.") sys.exit(0) first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() client.put("hc.apk", open("hc.apk", "rb").read()) client.disconnect()
notsent = [] for device in devices: print("Sending to %s..." % device) service_matches = bluetooth.find_service(name=b'OBEX Object Push', address=devices[device]) if len(service_matches) == 0: print("[W] %s not found, not sent." % device) notsent.append(device) else: first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() client.put(filename, json.dumps(assignments['matches'])) client.disconnect() print("Closed connection to %s." % device) for x in range(15): if len(notsent) == 0: break else: updatedList = [] for device in notsent: print("Sending to %s..." % device) service_matches = bluetooth.find_service(name=b'OBEX Object Push', address=devices[device]) print(service_matches)
from bluetooth import * from PyOBEX.client import Client import sys addr = sys.argv[1] file = sys.argv[2] print("Searching for OBEX service on %s" % addr) service_matches = find_service(uuid="00001105", address=addr) if len(service_matches) == 0: print("Couldn't find the service.") sys.exit(0) first_match = service_matches[0] port = first_match["port"] name = first_match["name"] host = first_match["host"] print("Connecting to \"%s\" on %s" % (name, host)) client = Client(host, port) client.connect() client.put(file, bytes("hii", 'UTF-8')) client.disconnect()