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 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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
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))
Exemplo n.º 8
0
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 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
Exemplo n.º 10
0
    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 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()
Exemplo n.º 13
0
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()
Exemplo n.º 14
0
    u'Hello World PJTINHA')

client = smpplib.client.Client('10.168.13.187', 9800)

# 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
Exemplo n.º 15
0
            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))
Exemplo n.º 16
0
def sent_handler(pdu):
    """
    """
    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,
Exemplo n.º 17
0
        log.info('error while trying to connect: {}'.format(unkn))
        return 0
    return client


def send_info(pdu):
    log.info(pdu.__dict__)
    request_analyze_v.request(client, pdu)


while 1:
    try:
        client = connect()
        request_analyze_v.list_of_objects = {}
        if client:
            client.set_message_received_handler(
                lambda pdu: send_info(pdu))
            # thr = Thread(target=client.listen)
            # thr.start()
            client.listen()

            # except AttributeError:
                # time.sleep(20)
                # continue
        else:
            time.sleep(20)
            continue
    except Exception as err:
        log.info('Error in connection: {}'.format(err.message))
        time.sleep(20)
        continue
Exemplo n.º 18
0
            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)
            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:
Exemplo n.º 20
0
#!/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()
Exemplo n.º 21
0
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()