def connect(): # (ip, port, sysId, passwd) = settings() (ip, port, sysId, passwd) = ("87.252.242.70", "900", "bElNeFT", "b4eLOIl") try: client = smpplib.client.Client(ip, port) client.connect() # TCP connection client.bind_transceiver(system_id=sysId, password=passwd) # SMPP connection except smpplib.exceptions.PDUError as pduer: log.info('error while trying to connect: {}'.format(pduer)) return 0 except smpplib.exceptions.ConnectionError as coner: log.info('error while trying to connect: {}'.format(coner)) return 0 except smpplib.exceptions.UnknownCommandError as unkn: log.info('error while trying to connect: {}'.format(unkn)) return 0 return client
def main(): global client, is_running, gf client = smpplib.client.Client(CLIENT_IP, CLIENT_PORT) # Print Output and Start Handler client.set_message_sent_handler(lambda pdu: logging.info( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD) print("TIC_TAC_TOE: Successfully bound SMPP") # Since bind was sucessful, we assume the show started. is_running = True th = Thread(target=client.listen) th.start() gf = t.GameFlow() while True: try: socketio.run(app, host='0.0.0.0', debug=False, use_reloader=False) break except KeyboardInterrupt: break except Exception as e: logging.exception('Error during listen' + str(e)) is_running = False
def main(): global client, is_running client = smpplib.client.Client(CLIENT_IP, CLIENT_PORT) # Print Output and Start Handler client.set_message_sent_handler( lambda pdu: logging.info('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() # Since bind was sucessful, we assume the show started. is_running = True t = Thread(target=process_sms_queue) t.start() while True: try: client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD) print("LED_WALL: Successfully bound SMPP") client.listen() break except AttributeError: print("Binding to smpp service FAILED. Retrying.") continue except KeyboardInterrupt: break except Exception as e: logging.exception('Error during listen' + str(e)) is_running = False
def sendBindTransceiver(self, client, system_id, password, system_type): print("Send bind trancv SystemID %s Password %s SystemType %s" % (system_id, password, system_type)) try: client.bind_transceiver(system_id=system_id, password=password, system_type=system_type) except: print("sendBindTransceiver Exception occured")
def send(self, recipient, title, message): """ Send notification to recipient :param str recipient: phone number :param str title: title for message (including in SMS) :param str message: short text message """ # Replace bad symbols in phone for char in '+()- ': recipient = recipient.replace(char, '') # Convert to unicode if type(title) != str: title = title.decode('utf-8') if type(message) != str: message = message.decode('utf-8') client = None if title: text = '%s:\n%s' % (title, message) else: text = message parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text) try: client = smpplib.client.Client(self.host, self.port) client.connect() if self.auth_pair: client.bind_transceiver( system_id=self.login, password=self.passwd) for part in parts: client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_ALNUM, source_addr_npi=smpplib.consts.SMPP_NPI_UNK, source_addr=self.source, dest_addr_ton=smpplib.consts.SMPP_TON_INTL, dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, destination_addr=recipient, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag ) except Exception as e: raise SendSMSException(e) finally: if client: try: client.unbind() except: pass client.disconnect() return False
def send_sms(*args): try: # if you want to know what's happening logging.basicConfig(filename='sms_smpp.log', filemode='w', level='DEBUG') # Two parts, UCS2, SMS with UDH parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(MESSAGE.get()) client = smpplib.client.Client(SMSC_HOST.get(), int(SMSC_PORT.get())) # Print when obtain message_id client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id)) ) client.set_message_received_handler( lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)) ) client.connect() if USER_TYPE.get() == "bind_transceiver": client.bind_transceiver(system_id=SYSTEM_ID.get(), password=SYSTEM_PASS.get()) if USER_TYPE.get() == "bind_transmitter": client.bind_transmitter(system_id=SYSTEM_ID.get(), password=SYSTEM_PASS.get()) for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, #source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure it is a byte string, not unicode: source_addr=SENDER_ID.get(), dest_addr_ton=smpplib.consts.SMPP_TON_INTL, #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode: destination_addr=DESTINATION_NO.get(), short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True, ) print(pdu.sequence) client.unbind() print('Unbind Done') client.disconnect() print('Disconnected') print('Sms sent on: ' + str(datetime.datetime.now())) except ValueError: pass
def connect(): # (ip, port, sysId, passwd) = settings() (ip, port, sysId, passwd, sys_type) = ("10.254.85.15", "2776", "belorusneft", "desWdf#!", "ussd") try: client = smpplib.client.Client(ip, port) client.connect() # TCP connection client.bind_transceiver(system_id=sysId, system_type=sys_type, password=passwd) # SMPP connection except smpplib.exceptions.PDUError as pduer: log.info('error while trying to connect: {}'.format(pduer)) return 0 except smpplib.exceptions.ConnectionError as coner: log.info('error while trying to connect: {}'.format(coner)) return 0 except smpplib.exceptions.UnknownCommandError as unkn: log.info('error while trying to connect: {}'.format(unkn)) return 0 return client
def smpp_client(request, smsc_inserter_image): client = smpplib.client.Client("127.0.0.1", 9000) def disconnect_client(): client.unbind() client.disconnect() request.addfinalizer(disconnect_client) # Print when obtain message_id client.set_message_received_handler( lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id="inserter-test", password="******") return client
def smpp_bind(client): while True: try: smpplib.client.logger.setLevel('INFO') client.set_message_received_handler(rx_deliver_sm) client.set_message_sent_handler(post_tx_message) #client.set_test_handler(my_test) #client.disconnect() client.connect() # Bind to OSMPP, out configured default-route in nitb. client.bind_transceiver(system_id="OSMPP", password="******") #client.test_handler(client, foo="bar") log.info('Listening....') client.listen([11]) except smpplib.exceptions.ConnectionError as e: print ("Connection Error (%s)" % e) client.disconnect() time.sleep(1)
def smpp_bind(client): while True: try: smpplib.client.logger.setLevel('INFO') client.set_message_received_handler(rx_deliver_sm) client.set_message_sent_handler(post_tx_message) #client.set_test_handler(my_test) #client.disconnect() client.connect() # Bind to OSMPP, out configured default-route in nitb. client.bind_transceiver(system_id="OSMPP", password="******") #client.test_handler(client, foo="bar") log.info('Listening....') client.listen([11]) except smpplib.exceptions.ConnectionError as e: print("Connection Error (%s)" % e) client.disconnect() time.sleep(1)
def sendMessage(myServer, myPort, system_id, password, phoneNumber, text): # if you want to know what's happening # logging.basicConfig(level='DEBUG') # Two parts, UCS2, SMS with UDH parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(text) try: client = smpplib.client.Client(myServer, myPort) # Print when obtain message_id client.set_message_sent_handler(lambda pdu: logging.info( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(lambda pdu: logging.info( 'delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id=system_id, password=password) for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, #source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure it is a byte string, not unicode: source_addr='', dest_addr_ton=smpplib.consts.SMPP_TON_INTL, #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode: destination_addr=phoneNumber, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True, ) time.sleep(1) client.disconnect() # client.listen() # t = threading.Thread(target=listen, args=(client,)) # t.start() except Exception as e: logging.info(str(e))
def send_message(source, dest, string): client = smpplib.client.Client('127.0.0.1', 2775) # Print when obtain message_id client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler( lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='OSMO-SMPP', password='******') parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string) #part = b"".join(parts) try: string.encode("ascii") coding = encoding_flag except: coding = smpplib.consts.SMPP_ENCODING_ISO10646 logging.info('Sending SMS "%s" to %s' % (string, dest)) for part in parts: pdu = client.send_message( msg_type=smpplib.consts.SMPP_MSGTYPE_USERACK, source_addr_ton=smpplib.consts.SMPP_TON_ALNUM, source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, source_addr=source, dest_addr_ton=smpplib.consts.SMPP_TON_INTL, dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, destination_addr=dest, short_message=part, data_coding=coding, esm_class=msg_type_flag, #esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD, registered_delivery=True, ) #print(pdu.generate()) logging.debug(pdu.sequence)
def handle(self, *args, **options): logging.basicConfig(level='DEBUG') try: op = options['op'] s = settings.SMPP[op] except: logging.error("no such config") exit() timeout = 15 if options['op'] == 'megafon': timeout = 60 client = smpplib.client.Client(s['ip'], s['port'], timeout) client.set_message_received_handler(mkGetPdu(op)) client.set_message_source(mkGenMessages(op, s['source'])) client.connect() client.bind_transceiver(system_id=s['system_id'], password=s['password']) try: client.listen([11]) except Exception as e: logging.error(e)
def bind_client(): logging.basicConfig(level='DEBUG') client = smpplib.client.Client('10.99.101.246', 2775) def getPdu(pdu): print(pdu.short_message.decode('utf-8')) print(type(pdu)) sql.save_des(randint(1, 1000000), "orginnn", pdu.short_message.decode('utf-8'),pdu.receipted_message_id) sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)) client.set_message_received_handler( lambda pdu: getPdu(pdu)) client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='rekik', password='******') client.listen() t = Thread(target=client.listen, args=()) t.daemon = True t.start() t.join() return
def main(): global client, messages f = open(MSG_FILE) logging.info('Opened file: {0!s}'.format(MSG_FILE)) for l in f: line = l.rstrip() splitted = line.split('|') time_range = splitted[0].split('-') one_line = [int(time_range[0]), int(time_range[1]), splitted[1]] messages.append(one_line) logging.info('file read and parsed') client = smpplib.client.Client(CLIENT_IP, CLIENT_PORT) # Print Output and Start Handler client.set_message_sent_handler(lambda pdu: logging.info( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() while True: try: client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD) print("MSGOFTHEDAY: Successfully bound SMPP") client.listen() logging.error('listend failed') break except KeyboardInterrupt: break except AttributeError: logging.error('Bind failed starting again.') continue except Exception as e: logging.exception('Error during listen' + str(e))
def send_to_jasmin_smpp_server(sender, reciver, message): logging.basicConfig(level='DEBUG') parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(message * 10) client = smpplib.client.Client('10.99.101.246', 2775) client.set_message_sent_handler( lambda pdu: sys.stdout.write('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler( lambda pdu: sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='rekik', password='******') for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure it is a byte string, not unicode: source_addr=sender, dest_addr_ton=smpplib.consts.SMPP_TON_INTL, # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode: destination_addr=reciver, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True, ) print(pdu.sequence) t = Thread(target=client.listen()) t.start()
def smpp_bind(): client = smpplib.client.Client("127.0.0.1", 2775, 90) client.set_message_received_handler(rx_alert_notification) client.connect() client.bind_transceiver(system_id="NOTIFY", password="******") client.listen()
source_addr_ton=smpplib.consts.SMPP_TON_INTL, # source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure it is a byte string, not unicode: source_addr=sender, dest_addr_ton=smpplib.consts.SMPP_TON_INTL, # dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode: destination_addr=receiver, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True, ) if __name__ == '__main__': client = smpplib.client.Client('localhost', 2775) client.set_message_sent_handler(message_sent_handler) client.set_message_received_handler(message_received_handler) client.connect() client.bind_transceiver(system_id='login', password='******') t = Thread(target=client.listen) t.start() context = {'send_message': send_message} embed(user_ns=context) code.interact(local=concurrent)
# Print when obtain message_id client.set_message_sent_handler(lambda pdu: sys.stdout.write( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) # Handle delivery receipts (and any MO SMS) def handle_deliver_sm(pdu): sys.stdout.write('delivered {}\n'.format(pdu.receipted_message_id)) return 0 # cmd status for deliver_sm_resp client.set_message_received_handler(lambda pdu: handle_deliver_sm(pdu)) client.connect() client.bind_transceiver(system_id='DYNAMO', password='******', system_type='dyn') for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_NWSPEC, #source_addr_ton=smpplib.consts.SMPP_TON_ALNUM, source_addr_npi=smpplib.consts.SMPP_NPI_UNK, # Make sure it is a byte string, not unicode: source_addr='5838', #source_addr='UPSTREAM', #smpplib.consts.SMPP_TON_UNK #smpplib.consts.SMPP_TON_ALNUM dest_addr_ton=smpplib.consts.SMPP_TON_INTL, dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode:
dest_addr_ton=smpplib.consts.SMPP_TON_INTL, dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, destination_addr=dest, short_message=part, data_coding=encoding_flag, #esm_class=msg_type_flag, esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD, registered_delivery=False, ) log.debug(pdu.sequence) client = smpplib.client.Client('127.0.0.1', 2775) # Print when obtain message_id client.set_message_sent_handler(lambda pdu: sys.stdout.write( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(lambda pdu: sys.stdout.write( 'delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='test', password='******') destinations = ('3802', '7839', '3807', '3811', '3806', '3805', '3804', '3809', '3812', '3815', '3814', '3803', '3813') for dest in destinations: send_message(dest, 'Mahlzeit') client.listen()
dest_addr_ton=smpplib.consts.SMPP_TON_INTL, dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, destination_addr=dest, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=False, ) client = smpplib.client.Client('127.0.0.1', 2775) # Print Output and Start Handler client.set_message_sent_handler(lambda pdu: logging.info('sent {} {}\n'.format( pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() client.bind_transceiver(system_id='YourESME', password='******') print "MYSERVICE: Successfully bound SMPP" while True: try: client.listen() break except KeyboardInterrupt: break except Exception as e: logging.exception('Error during listen' + str(e))
'DRIVER={SQL SERVER};SERVER="SERVER ADDRESS";Database="DATABASE NAME";UID="ID";PWD="Password"' ) sql = '''UPDATE TABLE_NAME SET Status='SMS Processed',FirstActionTime=GETDATE() WHERE ProcessNumber={} and MSISDN={} '''.format( idx, num) cursor = conn.cursor() cursor.execute(sql) conn.commit() text = str() df = pd.DataFrame() #Enter server address and port client = smpplib.client.Client('0.0.0.0', 80) client.connect() client.bind_transceiver(system_id='id', password='******') #getting our database table as pandas dataframe getDF() for row in df.itterrow(): text = row[1].SMSText parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts( u'{}'.format(text)) for part in parts: pdu = client.send_message( source_addr_ton=0, source_addr_npi=0, # Make sure it is a byte string, not unicode: source_addr='0000', dest_addr_ton=1, dest_addr_npi=1, # Make sure thease two params are byte strings, not unicode:
print("Received pdu %s" % pdu) def received_handler(pdu): """ """ print("Received pdu %s" % pdu) client = smpplib.client.Client(host="smpp1.mymobileapi.com", port=4075) client.set_message_sent_handler(sent_handler) client.set_message_received_handler(received_handler) client.connect() client.bind_transceiver(system_id="EUROCOM", password="******") Thread(target=client.listen).start() parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts("Testing this.") for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, source_addr="", dest_addr_ton=smpplib.consts.SMPP_TON_INTL, destination_addr="27813821298", short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True,
short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=False, ) client = smpplib.client.Client('127.0.0.1', 2775) # Print Output and Start Handler client.set_message_sent_handler( lambda pdu: logging.info('sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(handle_incoming_sms) client.connect() client.bind_transceiver(system_id='YourESME', password='******') print "MYSERVICE: Successfully bound SMPP" while True: try: client.listen() break except KeyboardInterrupt: break except Exception as e: logging.exception('Error during listen' + str(e))
#!/usr/bin/python3.5 import logging import sys import smpplib.gsm import smpplib.client import smpplib.consts #if you want to know what's happening #logging.basicConfig(level='DEBUG') # Two parts, UCS2, SMS with UDH parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(u'Привет мир!\n' * 10) client = smpplib.client.Client('172.16.29.10', 2775) # Print when obtain message_id client.set_message_sent_handler(lambda pdu: sys.stdout.write( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(lambda pdu: sys.stdout.write( 'delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='asiatec', password='******') client.listen()
DESTINATION_ADDR = '' # BODY status = 0 parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(MESSAGE) client = smpplib.client.Client(SERVER_ADDRESS, PORT) client.set_message_sent_handler(lambda pdu: sys.stdout.write( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) status += 1 client.set_message_received_handler(lambda pdu: sys.stdout.write( 'delivered {}\n'.format(pdu.receipted_message_id))) try: client.connect() client.bind_transceiver(system_id=SYSTEM_ID, password=PASSWORD) for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, source_addr=SOURCE_ADDR, dest_addr_ton=smpplib.consts.SMPP_TON_INTL, destination_addr=DESTINATION_ADDR, short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, ) except Exception: status = 0 finally: sys.stdout.write(str(status) + '\n')
# Two parts, UCS2, SMS with UDH parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(u'Sample Text\n' * 10) client = smpplib.client.Client('172.17.0.0', 3700, allow_unknown_opt_params=True) # Print when obtain message_id client.set_message_sent_handler(lambda pdu: sys.stdout.write( 'sent {} {}\n'.format(pdu.sequence, pdu.message_id))) client.set_message_received_handler(lambda pdu: sys.stdout.write( 'delivered {}\n'.format(pdu.receipted_message_id))) client.connect() client.bind_transceiver(system_id='username', password='******') for part in parts: pdu = client.send_message( source_addr_ton=smpplib.consts.SMPP_TON_INTL, #source_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure it is a byte string, not unicode: source_addr='3583', dest_addr_ton=smpplib.consts.SMPP_TON_INTL, #dest_addr_npi=smpplib.consts.SMPP_NPI_ISDN, # Make sure thease two params are byte strings, not unicode: destination_addr='0782499869', short_message=part, data_coding=encoding_flag, esm_class=msg_type_flag, registered_delivery=True,