コード例 #1
0
ファイル: test_sms.py プロジェクト: achiang/python-messaging
    def test_encoding_class(self):
        number = '2b3334363534313233343536'.decode('hex')
        text = "hey yo"
        expected_0 = "0001000B914356143254F6001006E8721E947F03"
        expected_1 = "0001000B914356143254F6001106E8721E947F03"
        expected_2 = "0001000B914356143254F6001206E8721E947F03"
        expected_3 = "0001000B914356143254F6001306E8721E947F03"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.klass = 0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_0)

        sms.klass = 1
        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_1)

        sms.klass = 2
        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_2)

        sms.klass = 3
        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_3)
コード例 #2
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_class(self):
        number = "+34654123456"
        text = "hey yo"
        expected_0 = "0001000B914356143254F6001006E8721E947F03"
        expected_1 = "0001000B914356143254F6001106E8721E947F03"
        expected_2 = "0001000B914356143254F6001206E8721E947F03"
        expected_3 = "0001000B914356143254F6001306E8721E947F03"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.klass = 0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_0)

        sms.klass = 1
        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_1)

        sms.klass = 2
        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_2)

        sms.klass = 3
        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected_3)
コード例 #3
0
    def exportMessage(self):
        logger.debug('exportMessage()')
        try:
            message = SmsSubmit(self._sTo, self._sMessage)
            return message.to_pdu()
        except:
            logger.error('Failed to encode message ' + self.toString())

        return ''
コード例 #4
0
 def send(self):
     self.pdu = SmsSubmit(self.recipient, self.content)
     for xpdu in self.pdu.to_pdu():
         command = 'AT+CMGS=%d\r' % xpdu.length
         self.SendCommand(command, len(str(xpdu.length)) + 14)
         command = '%s\x1a' % xpdu.pdu
         self.SendCommand(command, len(xpdu.pdu) + 20)
         self.logfile.write(str(datetime.now()))
         self.logfile.write('   after send a sms \n')
コード例 #5
0
 def send(self):
     self.pdu = SmsSubmit(self.recipient, self.content)
     for xpdu in self.pdu.to_pdu():
         command = 'AT+CMGS=%d\r' % xpdu.length
         a = self.SendCommand(command, len(str(xpdu.length)) + 14)
         command = '%s\x1a' % xpdu.pdu
         b = self.SendCommand(command, len(xpdu.pdu) + 20)
         data = str(a) + str(b)
         self.insertSentitem(self.recipient, self.content, data)
     return data
コード例 #6
0
ファイル: sms.py プロジェクト: achiang/wader
    def to_pdu(self, store=False):
        """Returns the PDU representation of this message"""
        sms = SmsSubmit(self.number, self.text)

        sms.csca = self.csca
        sms.request_status = self.status_request

        if store:
            sms.validity = None

        return sms.to_pdu()
コード例 #7
0
    def test_encoding_request_status(self):
        # tested with pduspy.exe and http://www.rednaxela.net/pdu.php
        number = codecs.decode(b'2b3334363534313233343536', 'hex')
        text = "hey yo"
        expected = "0021000B914356143254F6000006E8721E947F03"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.request_status = True

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #8
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_request_status(self):
        # tested with pduspy.exe and http://www.rednaxela.net/pdu.php
        number = '2b3334363534313233343536'.decode('hex')
        text = "hey yo"
        expected = "0021000B914356143254F6000006E8721E947F03"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.request_status = True

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #9
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_request_status(self):
        # tested with pduspy.exe and http://www.rednaxela.net/pdu.php
        number = "+34654123456"
        text = "hey yo"
        expected = "0021000B914356143254F6000006E8721E947F03"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.request_status = True

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #10
0
ファイル: protocol.py プロジェクト: smn/txgsm
    def send_sms(self, msisdn, text):
        sms = SmsSubmit(msisdn, text)
        # NOTE: The use of the Deferred here is a bit wonky
        #       I'm using it like this because it makes adding callbacks
        #       in a for-loop easier since we're potentially sending
        #       SMSs bigger than 160 chars.
        d = Deferred()
        for pdu in sms.to_pdu():
            d.addCallback(self.next("AT+CMGS=%d" % (pdu.length,), expect="> "))
            d.addCallback(self.next("%s%s" % (pdu.pdu, self.CTRL_Z)))

        d.callback([])
        return d
コード例 #11
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_8bit_message(self):
        number = "01000000000"
        csca = "+44000000000"
        text = "Hi there..."
        expected = "07914400000000F001000B811000000000F000040B48692074686572652E2E2E"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.csca = csca
        sms.fmt = 0x04  # 8 bits

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #12
0
ファイル: serialmodem.py プロジェクト: SEL-Columbia/easygsm
 def send_sms(self, number, text, callback_index=None):
     if self.mode == 0:
         sms = SmsSubmit(number, text)
         pdu = sms.to_pdu()[0]
         message_list = [("AT+CMGS=%d" % (pdu.length,), 
                          pdu.pdu,
                          callback_index)]
     else:
         message_list = [("AT+CMGS=%s" % (number,), 
                          text,
                          callback_index)]
     
     self._pending.extend(message_list)
     self._write_next()
コード例 #13
0
ファイル: protocol.py プロジェクト: yeekzhang/txgsm
    def send_sms(self, msisdn, text):
        sms = SmsSubmit(msisdn, text)
        # NOTE: The use of the Deferred here is a bit wonky
        #       I'm using it like this because it makes adding callbacks
        #       in a for-loop easier since we're potentially sending
        #       SMSs bigger than 160 chars.
        d = Deferred()
        for pdu in sms.to_pdu():
            d.addCallback(self.next('AT+CMGS=%d' % (pdu.length, ),
                                    expect='> '))
            d.addCallback(self.next('%s%s' % (pdu.pdu, self.CTRL_Z)))

        d.callback([])
        return d
コード例 #14
0
ファイル: smsgateway.py プロジェクト: paulbsd/smsgateway
def pduformat(phonenumber, message):
    """
    Formats SMS using pdu encoding
    :param phonenumber: Phone number to insert in pdu
    :param message: Text message
    :return: pdustring, pdulenght
    """
    sms = SmsSubmit(phonenumber, message)
    pdu = sms.to_pdu()[0]
    pdustring = pdu.pdu
    pdulength = pdu.length
    # debug output
    # print(phonenumber, message)
    # print(pdu.length, pdu.pdu)
    return pdustring, pdulength
コード例 #15
0
def sendLongMessage(modem, number, message):
    modem.write('AT+CMGF=0\r')
    time.sleep(0.5)
    sms = SmsSubmit(number, message)
    for pdu in sms.to_pdu():
        print('sending')
        strS = 'AT+CMGS=' + str(len(pdu.pdu) / 2 - 1) + '\r\n'
        modem.write(strS)
        time.sleep(0.5)
        modem.write(pdu.pdu + '\r')
        time.sleep(0.5)
        modem.write(chr(26))
        time.sleep(0.5)
        print('done')
    modem.write('AT+CMGF=1\r')
    time.sleep(0.5)
コード例 #16
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_csca(self):
        number = '2b3334363136353835313139'.decode('hex')
        text = "hola"
        csca = "+34646456456"
        expected = "07914346466554F601000B914316565811F9000004E8373B0C"
        expected_len = 17

        sms = SmsSubmit(number, text)
        sms.csca = csca
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
        self.assertEqual(pdu.length, expected_len)
        self.assertEqual(pdu.cnt, 1)
        self.assertEqual(pdu.seq, 1)
コード例 #17
0
def send_text(number, text, path='/dev/ttyUSB0'):
    sms = SmsSubmit(number, text)
    pdu = sms.to_pdu()[0]

    # print len(sms.to_pdu())

    # open the modem port (assumes Linux)
    ser = serial.Serial(path, timeout=1)
    # write the PDU length and wait 1 second till the
    # prompt appears (a more robust implementation
    # would wait till the prompt appeared)
    ser.write('AT+CMGS=%d\r' % pdu.length)
    print ser.readlines()
    # write the PDU and send a ctrl+z escape
    ser.write('%s\x1a' % pdu.pdu)
    ser.close()
コード例 #18
0
ファイル: utils.py プロジェクト: bangcht/smsremote
def sendLongMessage(modem, number, message):
    modem.write('AT+CMGF=0\r')
    time.sleep(0.5)
    sms = SmsSubmit(number, message)
    for pdu in sms.to_pdu():
        print('sending')
        strS = 'AT+CMGS=' + str(len(pdu.pdu) / 2 - 1) + '\r\n'
        modem.write(strS)
        time.sleep(0.5)
        modem.write(pdu.pdu + '\r');
        time.sleep(0.5)
        modem.write(chr(26))
        time.sleep(0.5)
        print('done')
    modem.write('AT+CMGF=1\r')
    time.sleep(0.5)
コード例 #19
0
    def sendSMS(self, cpid, oth, msg, smsid):
        # Called by PhoneMo 3401
        #   1   Pack SMS to pdu string
        #   2   Format other number
        #   3   Gen new SMS id
        #   4   raise 603 if user don't have this chip
        #   5   Set Sms info

        # sms = SmsSubmit(oth, msg)
        # pdu = sms.to_pdu()[0]
        now = int(time.time()*1000)
        (fnum, inum, loc) = phoneNum.loads(oth)
        # smsid = "%s%d%d"%(inum, now, random.randrange(100, 999))
        now = now/1000
        _script = """
            local bid = redis.call('hget', 'Chip:'..KEYS[1]..':info', 'bid')
            local csc = redis.call('zscore', 'Box:'..bid..':Chips', KEYS[1])
            local sc = redis.call('zscore', 'User:'******':Boxes', bid)
            local cp = {}
            if csc == nil then
                return {'0'}
            end
            if sc ~= nil then
                cp = redis.call('hmget', 'Chip:'..KEYS[1]..':info', 'id', 'mod', 'cdid', 'bid', 'sid', 'chn')
                redis.call('hmset', 'Sms:'..KEYS[3]..':info', 'id', KEYS[3], 'cpid', cp[1], 'cdid', cp[3], 'bid', cp[4], 'uid', KEYS[2], 'oth', KEYS[4], 'fnum', KEYS[5], 'inum', KEYS[6], 'loc', KEYS[7], 'msg', KEYS[8], 'st', KEYS[9])
            end
            return cp
        """
        d = self._redis.eval(_script, [cpid, self.id, smsid, oth, fnum, inum, loc, base64.b64encode(msg.encode('utf8')), now])
        d.addCallback(lambda hs: raiseCode(701) if len(hs) == 1 else hs)
        d.addCallback(lambda hs: Chip(cpid, dict(zip(['id', 'mod', 'cdid', 'bid', 'sid', 'chn'], hs))) if len(hs) > 0 else raiseCode(603))
        d.addCallback(lambda cp: [cp, SmsSubmit(oth, msg).to_pdu()[0] if cp['mod'] == 'MG2639' else CdmaSmsSubmit(oth, msg).to_pdu()[0]])
        d.addCallback(lambda cs: [cs[0], [cs[0].id, 4, smsid, 0x00, 10, '', 'AT+CMGS=%d\r'%cs[1].length, '%s\x1a'%cs[1].pdu] if cs[0]['mod'] == 'MG2639' else [cs[0].id, 4, smsid, 0x00, 10, '', 'AT+CMGS=%d\r%s\x1a'%(cs[1].length, cs[1].pdu)]])
        # d.addCallback(lambda cs: [cs[0], [cs[1][0], cs[1][1].length, cs[1][1].pdu]])
        return d
コード例 #20
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_csca(self):
        number = "+34616585119"
        text = "hola"
        csca = "+34646456456"
        expected = "07914346466554F601000B914316565811F9000004E8373B0C"
        expected_len = 17

        sms = SmsSubmit(number, text)
        sms.csca = csca
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
        self.assertEqual(pdu.length, expected_len)
        self.assertEqual(pdu.cnt, 1)
        self.assertEqual(pdu.seq, 1)
コード例 #21
0
    def test_encoding_csca(self):
        number = codecs.decode(b'2b3334363136353835313139', 'hex').decode()
        text = "hola"
        csca = "+34646456456"
        expected = "07914346466554F601000B914316565811F9000004E8373B0C"
        expected_len = 17

        sms = SmsSubmit(number, text)
        sms.csca = csca
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
        self.assertEqual(pdu.length, expected_len)
        self.assertEqual(pdu.cnt, 1)
        self.assertEqual(pdu.seq, 1)
コード例 #22
0
ファイル: test.py プロジェクト: zhangsz0516/sms_send
def send_sms(ser_port, phone_num, content):
    phone = "+86{0}".format(phone_num)
    pdu = SmsSubmit(phone, content).to_pdu()[0]

    ser_port.write('AT+CMGS=%d\r' % pdu.length)
    print ser_port.readlines()  #注意:必须读取,但返回没有ok
    ser_port.write('%s\x1a' % pdu.pdu)
    return read_result(ser_port)
コード例 #23
0
def smsSubmit(args):

    from messaging.sms import SmsSubmit
    from datetime import datetime

    text = ''.join(map(unichr, args["text_as_char_code_arr"]))

    sms = SmsSubmit(args["number"], text)

    if "csca" in args:
        sms.csca = args["csca"]

    if "validity" in args:
        sms.validity = datetime.strptime(args["validity"],
                                         "%a, %d %b %Y %H:%M:%S %Z")

    if "klass" in args:
        sms.klass = args["klass"]

    if "request_status" in args:
        sms.request_status = args["request_status"]

    out = []

    for pdu in sms.to_pdu():
        out.append(pdu.__dict__)

    return out
コード例 #24
0
ファイル: spong.py プロジェクト: awangga/spy
 def send(self):
     self.pdu = SmsSubmit(self.recipient, self.content)
     for xpdu in self.pdu.to_pdu():
         command = "AT+CMGS=%d\r" % xpdu.length
         self.SendCommand(command, len(str(xpdu.length)) + 14)
         command = "%s\x1a" % xpdu.pdu
         self.SendCommand(command, len(xpdu.pdu) + 20)
         self.logfile.write(str(datetime.now()))
         self.logfile.write("   after send a sms \n")
コード例 #25
0
ファイル: wurlitzer.py プロジェクト: sehaas/gsmwurlitzer
 def __handle_sms(self, pdu):
     sms = SmsDeliver(pdu)
     print_dbg('SMS from:', sms.number, 'text:', sms.text)
     cmd = sms.text.split(None, 1)[0]  # only use first word
     if cmd in self.playlist.keys():
         song = self.playlist.get(cmd)
         print_dbg('PLAY: ', cmd)
         self.__place_call(sms.number, song)
     else:
         print_dbg('SEND PLAYLIST')
         response = SmsSubmit(
             sms.number,
             'Select song:\n> ' + '\n> '.join(self.playlist.keys()))
         for resp_pdu in response.to_pdu():
             print_dbg('RESP:', resp_pdu.pdu)
             # cannot wait for response '> ' due to missing '\r'
             self.command(b'AT+CMGS=%d' % resp_pdu.length, None)
             time.sleep(1)  # just wait 1sec instead
             self.command(b'%s\x1a' % resp_pdu.pdu)
コード例 #26
0
ファイル: smsweb.py プロジェクト: awangga/spy
 def send(self):
     self.pdu = SmsSubmit(self.recipient, self.content)
     for xpdu in self.pdu.to_pdu():
         command = "AT+CMGS=%d\r" % xpdu.length
         a = self.SendCommand(command, len(str(xpdu.length)) + 14)
         command = "%s\x1a" % xpdu.pdu
         b = self.SendCommand(command, len(xpdu.pdu) + 20)
         data = str(a) + str(b)
         self.insertSentitem(self.recipient, self.content, data)
     return data
コード例 #27
0
ファイル: modem.py プロジェクト: ArmiT/smssender
    def send_sms_pdu(self, phone, text):
        """
        Sends sms, that contains text, to the phone in the PDU mode. Payload can contain utf-8 range and length,
        that less or equal 70 symbols. If payload contain only ascii range, then length may be less or equal 160 symbols
        Attention! Method does not have validation!
        :param phone: string - receiver phone number
        :param text: string - payload
        :return: boolean - Returns a True if message sent successfully, otherwise False
        """

        # sms = SmsSubmit(phone, text.decode("utf-8"))
        sms = SmsSubmit(phone, text)
        pdu = sms.to_pdu()[0]
        time.sleep(2)
        self.connection.write("AT+CMGF=0\x0D")  # enter pdu mode
        self.connection.readline()
        time.sleep(2)
        self.connection.write("AT+CMGS=%s\x0D%s\x1A" % (pdu.length, pdu.pdu))

        return self.check_response()
コード例 #28
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_multipart_7bit(self):
        # text encoded with umts-tools
        text = "Or walk with Kings - nor lose the common touch, if neither foes nor loving friends can hurt you, If all men count with you, but none too much; If you can fill the unforgiving minute With sixty seconds' worth of distance run, Yours is the Earth and everything thats in it, And - which is more - you will be a Man, my son"
        number = "655345678"
        expected = [
            "005100098156355476F80000AAA00500038803019E72D03DCC5E83EE693A1AB44CBBCF73500BE47ECB41ECF7BC0CA2A3CBA0F1BBDD7EBB41F4777D8C6681D26690BB9CA6A3CB7290F95D9E83DC6F3988FDB6A7DD6790599E2EBBC973D038EC06A1EB723A28FFAEB340493328CC6683DA653768FCAEBBE9A07B9A8E06E5DF7516485CA783DC6F7719447FBF41EDFA18BD0325CDA0FCBB0E1A87DD",
            "005100098156355476F80000AAA005000388030240E6349B0DA2A3CBA0BADBFC969FD3F6B4FB0C6AA7DD757A19744DD3D1A0791A4FCF83E6E5F1DB4D9E9F40F7B79C8E06BDCD20727A4E0FBBC76590BCEE6681B2EFBA7C0E4ACF41747419540CCBE96850D84D0695ED65799E8E4EBBCF203A3A4C9F83D26E509ACE0205DD64500B7447A7C768507A0E6ABFE565500B947FD741F7349B0D129741",
            "005100098156355476F80000AA14050003880303C2A066D8CD02B5F3A0F9DB0D",
        ]

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.rand_id = 136
        sms.validity = timedelta(days=4)

        ret = sms.to_pdu()
        cnt = len(ret)
        for i, pdu in enumerate(ret):
            self.assertEqual(pdu.pdu, expected[i])
            self.assertEqual(pdu.seq, i + 1)
            self.assertEqual(pdu.cnt, cnt)
コード例 #29
0
def pdu_format(phonenumber, message):
    """
    Formats SMS using pdu encoding
    :param phonenumber: Phone number to insert in pdu
    :param message: Text message
    :return: pdustring, pdulenght
    """
    # Whitelist char
    whitelist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    whitelist = whitelist + range(0, 9)
    whitelist = whitelist + [' ', '-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
    fixed_message = ""
    for chr in message:
        if chr in whitelist:
            fixed_message += chr
        else:
            fixed_message += "."

    sms = SmsSubmit(phonenumber, fixed_message)
    pdu = sms.to_pdu()[0]
    pdustring = pdu.pdu
    pdulength = pdu.length
    return pdustring, pdulength, phonenumber, fixed_message
コード例 #30
0
    def send(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        self.pdu = SmsSubmit(self.recipient, self.content)
        for xpdu in self.pdu.to_pdu():
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('send CMGS\n')
	        command = 'AT+CMGS=%d\r' % xpdu.length
	        self.SendCommand(command,getline=True)
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 1 CMGS\n')
	        data = self.ser.readall()
	        print data
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 2 CMGS\n')
	        command = '%s\x1a' % xpdu.pdu
	        self.SendCommand(command,getline=True)
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 3 CMGS\n')
	        data = self.ser.readall()
	        print data
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 4 CMGS\n')
コード例 #31
0
ファイル: sms.py プロジェクト: tcriess/meteorolopi
 def send(self, message):
     # d = self.sendcommand(b"AT+CMGF=1", 10)
     # if d == b"\r\nOK\r\n":
     #    c = 'AT+CMGS="{0}"'.format(self.number).encode('utf-8')
     #    d = self.sendcommand(c, 10)
     #    if d == b"\r\n> ":
     #        message += "\x1a"
     #        d = self.sendcommand(message.encode('utf-8'), 10)
     d = self._sendcommand(b"AT+CMGF=0", 6)
     if d == b"\r\nOK\r\n":
         s = SmsSubmit(self.tonumber, message)
         pdus = s.to_pdu()
         for pdu in pdus:
             c = 'AT+CMGS={0}'.format(pdu.length).encode('utf-8')
             d = self._sendcommand(c, 4)
             if d == b"\r\n> ":
                 data = pdu.pdu[:]
                 data += "\x1a"
                 d = self._sendcommand(data.encode('utf-8'), 10)
             else:
                 self._sendcommand(b'\x1b', 10)
                 self._sendcommand(b'\x1a', 10)
     return d
コード例 #32
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_ucs2_message(self):
        number = '2b3334363136353835313139'.decode('hex')
        text = u'あ叶葉'
        csca = '+34646456456'
        expected = "07914346466554F601000B914316565811F9000806304253F68449"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.csca = csca

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        text = u"Русский"
        number = '363535333435363738'.decode('hex')
        expected = "001100098156355476F80008AA0E0420044304410441043A04380439"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #33
0
 def putsms(self, MSISDN, Message):
     Message = fixNonASCII(Message)
     if self.merk in conf.unrecognize_character:
         Message = fixUnrecognizeChr(Message)
     if self.smsFormat == SMS_TEXT:
         if self.merk in conf.sms_dest_without_sign:
             MSISDN = MSISDN.lstrip('+')
         self.send('AT+CMGS="%s"' % MSISDN)
         Message = Message[:160]
         self.sendExpect(Message, 'CMGS', end=chr(26))
     else:
         self.log('KIRIM SMS %s' % {'msisdn': MSISDN, 'message': Message})
         for pdu in SmsSubmit(MSISDN, Message).to_pdu():
             self.send('AT+CMGS="%s"' % pdu.length)
             Message = pdu.pdu
             self.sendExpect(Message, 'CMGS', end=chr(26))
     return self.unbusy(self.sent)
コード例 #34
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_message_with_latin1_chars(self):
        # tested with pduspy.exe
        number = '2b3334363534313233343536'.decode('hex')
        text = u"Hölä"
        expected = "0011000B914356143254F60000AA04483E7B0F"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        # tested with pduspy.exe
        number = '2b3334363534313233343536'.decode('hex')
        text = u"BÄRÇA äñ@"
        expected = "0001000B914356143254F6000009C2AD341104EDFB00"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #35
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_8bit_message(self):
        number = "01000000000"
        csca = "+44000000000"
        text = "Hi there..."
        expected = "07914400000000F001000B811000000000F000040B48692074686572652E2E2E"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.csca = csca
        sms.fmt = 0x04  # 8 bits

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #36
0
ファイル: sms_handler.py プロジェクト: RajatShukla/Test
    def generateSmsSubmitPdu(self):
        smsPdus = []
        smsDelvObj = SmsSubmit(self._address, self._smsText)
        smsDelvObj._set_csca(self._smscAddress)
        print("Encoding Type:", self._encodingType)
        if ( self._encodingType == 0):
            smsDelvObj.dcs = 0x00
        if ( self._encodingType == 8):
            smsDelvObj.dcs = 0x08

        for i in smsDelvObj.to_pdu():
            smsPdus.append(i.pdu)
        return smsPdus
コード例 #37
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_ucs2_message(self):
        number = "+34616585119"
        text = u'あ叶葉'
        csca = '+34646456456'
        expected = "07914346466554F601000B914316565811F9000806304253F68449"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.csca = csca

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        text = u"Русский"
        number = "655345678"
        expected = "001100098156355476F80008AA0E0420044304410441043A04380439"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #38
0
    def test_encoding_ucs2_message(self):
        number = codecs.decode(b'2b3334363136353835313139', 'hex').decode()
        text = u'あ叶葉'
        csca = '+34646456456'
        expected = "07914346466554F601000B914316565811F9000806304253F68449"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.csca = csca

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        text = u"Русский"
        number = codecs.decode(b'363535333435363738', 'hex').decode()
        expected = "001100098156355476F80008AA0E0420044304410441043A04380439"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #39
0
    def _textbuffer_changed(self, textbuffer):
        """Handler for the textbuffer changed signal"""
        text = textbuffer.get_text(textbuffer.get_start_iter(),
                                   textbuffer.get_end_iter())
        if not len(text):
            msg = _('Text message: 0/%d chars') % SEVENBIT_SIZE
        else:
            # get the number of messages
            # we use a default number for encoding purposes
            num_sms = len(SmsSubmit('+342453435', text).to_pdu())
            if num_sms == 1:
                max_length = SEVENBIT_SIZE if is_gsm_text(text) else UCS2_SIZE
                args = dict(num=len(text), total=max_length)
                msg = _('Text message: %(num)d/%(total)d chars') % args
            else:
                max_length = SEVENBIT_MP_SIZE if is_gsm_text(
                    text) else UCS2_MP_SIZE
                used = len(text) - (max_length * (num_sms - 1))
                args = dict(num=used, total=max_length, msgs=num_sms)
                msg = _('Text message: '
                        '%(num)d/%(total)d chars (%(msgs)d SMS)') % args

        self.view.get_top_widget().set_title(msg)
コード例 #40
0
ファイル: sms_sender.py プロジェクト: zhangsz0516/sms_send
def send_sms(ser_port, phone_num, content):
    phone = "+86{0}".format(phone_num)
    ctns = []
    if is_chinese(content):
        if len(content) > 60:
            ctns = cut_str_len(content, 60)
        else:
            ctns.append(content)
    else:
        if len(content) > 128:
            ctns = cut_str_len(content, 128)
        else:
            ctns.append(content)

    #sending
    results = []
    for ctn in ctns:
        pdu = SmsSubmit(phone, ctn).to_pdu()[0]
        ser_port.write('AT+CMGS=%d\r' % pdu.length)
        print ser_port.readlines()  #注意:必须读取,但返回没有ok
        ser_port.write('%s\x1a' % pdu.pdu)
        results.append(read_result(ser_port))

    return results
コード例 #41
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_message_with_latin1_chars(self):
        # tested with pduspy.exe
        number = "+34654123456"
        text = u"Hölä"
        expected = "0011000B914356143254F60000AA04483E7B0F"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        # tested with pduspy.exe
        number = "+34654123456"
        text = u"BÄRÇA äñ@"
        expected = "0001000B914356143254F6000009C2AD341104EDFB00"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
コード例 #42
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_multipart_7bit(self):
        # text encoded with umts-tools
        text = "Or walk with Kings - nor lose the common touch, if neither foes nor loving friends can hurt you, If all men count with you, but none too much; If you can fill the unforgiving minute With sixty seconds' worth of distance run, Yours is the Earth and everything thats in it, And - which is more - you will be a Man, my son"
        number = '363535333435363738'.decode('hex')
        expected = [
            "005100098156355476F80000AAA00500038803019E72D03DCC5E83EE693A1AB44CBBCF73500BE47ECB41ECF7BC0CA2A3CBA0F1BBDD7EBB41F4777D8C6681D26690BB9CA6A3CB7290F95D9E83DC6F3988FDB6A7DD6790599E2EBBC973D038EC06A1EB723A28FFAEB340493328CC6683DA653768FCAEBBE9A07B9A8E06E5DF7516485CA783DC6F7719447FBF41EDFA18BD0325CDA0FCBB0E1A87DD",
            "005100098156355476F80000AAA005000388030240E6349B0DA2A3CBA0BADBFC969FD3F6B4FB0C6AA7DD757A19744DD3D1A0791A4FCF83E6E5F1DB4D9E9F40F7B79C8E06BDCD20727A4E0FBBC76590BCEE6681B2EFBA7C0E4ACF41747419540CCBE96850D84D0695ED65799E8E4EBBCF203A3A4C9F83D26E509ACE0205DD64500B7447A7C768507A0E6ABFE565500B947FD741F7349B0D129741",
            "005100098156355476F80000AA14050003880303C2A066D8CD02B5F3A0F9DB0D",
        ]

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.rand_id = 136
        sms.validity = timedelta(days=4)

        ret = sms.to_pdu()
        cnt = len(ret)
        for i, pdu in enumerate(ret):
            self.assertEqual(pdu.pdu, expected[i])
            self.assertEqual(pdu.seq, i + 1)
            self.assertEqual(pdu.cnt, cnt)
コード例 #43
0
    def test_encoding_multipart_7bit_egsm(self):
        # text encoded with umts-tools
        self.maxDiff = None
        text = '€' * 229 + 'x'
        number = binascii.unhexlify(b'363535333435363738').decode()
        expected = [
            "005100098156355476F80000AAA005000388030136E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437",
            "005100098156355476F80000AAA0050003880302CA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA9BF2A6BC296FCA",
            "005100098156355476F80000AAA005000388030336E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE9437E54D7953DE94F1",
        ]

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.rand_id = 136
        sms.validity = timedelta(days=4)

        ret = sms.to_pdu()
        cnt = len(ret)
        for i, pdu in enumerate(ret):
            self.assertEqual(pdu.pdu, expected[i])
            self.assertEqual(pdu.seq, i + 1)
            self.assertEqual(pdu.cnt, cnt)
コード例 #44
0
ファイル: smsweb.py プロジェクト: awangga/spy
class SmsWeb(object):
    def __init__(self, recipient=config.recipient, message=config.message):
        self.recipient = recipient
        self.content = message

    def openser(self):
        self.ser = serial.Serial(config.serial, 115200, timeout=config.timeout)
        self.ser.flushInput()
        self.ser.flushOutput()
        self.SendCommand("ATZ\r", 8)
        self.SendCommand("AT+CMGF=0\r", 16)

    def opendb(self):
        self.conn = pymongo.MongoClient(config.mongohost, config.mongoport)
        self.db = self.conn.smsweb

    def insertOutbox(self, rcpt, msg):
        self.db.outbox
        doc = {"rcpt": rcpt, "msg": msg, "timestamp": datetime.now()}
        idProcess = self.db.outbox.insert_one(doc).inserted_id
        ret = {"rcpt": rcpt, "msg": msg, "idProcess": idProcess}
        return ret

    def insertSentitem(self, rcpt, msg, stat):
        self.db.sentitems
        doc = {"rcpt": rcpt, "msg": msg, "timestamp": str(datetime.now()), "idProcess": self.idprocess, "stat": stat}
        return self.db.sentitems.insert_one(doc).inserted_id

    def insertInbox(self, data):
        self.db.inbox
        return self.db.inbox.insert_one(data).inserted_id

    def getSentitem(self, id):
        self.db.sentitems
        return self.db.sentitems.find_one({"idProcess": id})

    def getSentitems(self):
        self.db.sentitems
        return self.db.sentitems.find()

    def getOutbox(self):
        self.db.outbox
        return self.db.outbox.find_one()

    def getOutboxs(self):
        self.db.outbox
        return self.db.outbox.find()

    def getInbox(self):
        self.db.inbox
        return self.db.inbox.find_one()

    def removeOutbox(self, id):
        self.db.outbox
        return self.db.outbox.delete_many({"_id": id})

    def dropOutbox(self):
        self.db.drop_collection("outbox")

    def rcpt(self, number):
        self.recipient = number

    def msg(self, message):
        self.content = message

    def idProcess(self, idprocess):
        self.idprocess = idprocess

    def sends(self):
        rcptarr = re.split(",|;", self.recipient)
        for num in rcptarr:
            if num:
                print "*Sending SMS to: " + num + " \n"
                self.rcpt(num)
                self.send()

    def send(self):
        self.pdu = SmsSubmit(self.recipient, self.content)
        for xpdu in self.pdu.to_pdu():
            command = "AT+CMGS=%d\r" % xpdu.length
            a = self.SendCommand(command, len(str(xpdu.length)) + 14)
            command = "%s\x1a" % xpdu.pdu
            b = self.SendCommand(command, len(xpdu.pdu) + 20)
            data = str(a) + str(b)
            self.insertSentitem(self.recipient, self.content, data)
        return data

    def close(self):
        self.ser.close()

    def SendCommand(self, command, char, getline=True):
        self.ser.write(command)
        data = ""
        if getline:
            data = self.ReadLine(char)
        return data

    def ReadAll(self):
        data = self.ser.readall()
        return data

    def ReadLine(self, char):
        data = self.ser.read(char)
        return data

    def unreadMsg(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = "AT+CMGL=0\r\n"
        data = self.SendCommand(command, 16)
        return data

    def readMsg(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = "AT+CMGL=1\r\n"
        self.ser.write(command)
        cmd = self.ser.readline()
        cmd += self.ser.readline()
        head = self.ser.readline()
        a = []
        while "CMGL" in head:
            data = self.ser.readline()
            sms = SmsDeliver(data.rstrip())
            idx = head.rstrip().split(",")[0].split(" ")[1]
            self.insertInbox(sms.data)
            # print idx
            a.append(int(idx))
            head = self.ser.readline()
        return a

    def allMsg(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = "AT+CMGL=4\r\n"
        data = self.SendCommand(command, 16)
        return data

    def deleteMsg(self, idx):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = "AT+CMGD=%s\r\n" % idx
        return self.SendCommand(command, 18)
        # self.ser.write(command)
        # data = self.ser.readline()
        # data += self.ser.readline()
        # data += self.ser.readline()
        # return data

    def deleteMsgs(self, idx):
        # self.ser.flushInput()
        # self.ser.flushOutput()
        for id in idx:
            command = "AT+CMGD=%s\r\n" % id
            self.SendCommand(command, 18)

    def getMsg(self, idx):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = "AT+CMGR=%s\r\n" % idx
        self.ser.write(command)
        data = self.ser.readline()
        data += self.ser.readline()
        data3 = self.ser.readline()
        data = data + data3
        if "CMGR" in data3:
            data += self.ser.readline()
            data += self.ser.readline()
            data += self.ser.readline()
        return data

    def isRunning(self, pid):
        path = "/proc/" + str(pid)
        return os.path.exists(path)
コード例 #45
0
class SmsWeb(object):
    def __init__(self, recipient=config.recipient, message=config.message):
        self.recipient = recipient
        self.content = message

    def openser(self):
        self.ser = serial.Serial(config.serial, 115200, timeout=config.timeout)
        self.ser.flushInput()
        self.ser.flushOutput()
        self.SendCommand('ATZ\r', 8)
        self.SendCommand('AT+CMGF=0\r', 16)

    def opendb(self):
        self.conn = pymongo.MongoClient(config.mongohost, config.mongoport)
        self.db = self.conn.smsweb

    def insertOutbox(self, rcpt, msg):
        self.db.outbox
        doc = {"rcpt": rcpt, "msg": msg, "timestamp": datetime.now()}
        idProcess = self.db.outbox.insert_one(doc).inserted_id
        ret = {"rcpt": rcpt, "msg": msg, "idProcess": idProcess}
        return ret

    def insertSentitem(self, rcpt, msg, stat):
        self.db.sentitems
        doc = {
            "rcpt": rcpt,
            "msg": msg,
            "timestamp": str(datetime.now()),
            "idProcess": self.idprocess,
            "stat": stat
        }
        return self.db.sentitems.insert_one(doc).inserted_id

    def insertInbox(self, data):
        self.db.inbox
        return self.db.inbox.insert_one(data).inserted_id

    def getSentitem(self, id):
        self.db.sentitems
        return self.db.sentitems.find_one({"idProcess": id})

    def getSentitems(self):
        self.db.sentitems
        return self.db.sentitems.find()

    def getOutbox(self):
        self.db.outbox
        return self.db.outbox.find_one()

    def getOutboxs(self):
        self.db.outbox
        return self.db.outbox.find()

    def getInbox(self):
        self.db.inbox
        return self.db.inbox.find_one()

    def removeOutbox(self, id):
        self.db.outbox
        return self.db.outbox.delete_many({"_id": id})

    def dropOutbox(self):
        self.db.drop_collection("outbox")

    def rcpt(self, number):
        self.recipient = number

    def msg(self, message):
        self.content = message

    def idProcess(self, idprocess):
        self.idprocess = idprocess

    def sends(self):
        rcptarr = re.split(',|;', self.recipient)
        for num in rcptarr:
            if num:
                print '*Sending SMS to: ' + num + ' \n'
                self.rcpt(num)
                self.send()

    def send(self):
        self.pdu = SmsSubmit(self.recipient, self.content)
        for xpdu in self.pdu.to_pdu():
            command = 'AT+CMGS=%d\r' % xpdu.length
            a = self.SendCommand(command, len(str(xpdu.length)) + 14)
            command = '%s\x1a' % xpdu.pdu
            b = self.SendCommand(command, len(xpdu.pdu) + 20)
            data = str(a) + str(b)
            self.insertSentitem(self.recipient, self.content, data)
        return data

    def close(self):
        self.ser.close()

    def SendCommand(self, command, char, getline=True):
        self.ser.write(command)
        data = ''
        if getline:
            data = self.ReadLine(char)
        return data

    def ReadAll(self):
        data = self.ser.readall()
        return data

    def ReadLine(self, char):
        data = self.ser.read(char)
        return data

    def unreadMsg(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGL=0\r\n'
        data = self.SendCommand(command, 16)
        return data

    def readMsg(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGL=1\r\n'
        self.ser.write(command)
        cmd = self.ser.readline()
        cmd += self.ser.readline()
        head = self.ser.readline()
        a = []
        while "CMGL" in head:
            data = self.ser.readline()
            sms = SmsDeliver(data.rstrip())
            idx = head.rstrip().split(',')[0].split(' ')[1]
            self.insertInbox(sms.data)
            #print idx
            a.append(int(idx))
            head = self.ser.readline()
        return a

    def allMsg(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGL=4\r\n'
        data = self.SendCommand(command, 16)
        return data

    def deleteMsg(self, idx):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGD=%s\r\n' % idx
        return self.SendCommand(command, 18)
        #self.ser.write(command)
        #data = self.ser.readline()
        #data += self.ser.readline()
        #data += self.ser.readline()
        #return data

    def deleteMsgs(self, idx):
        #self.ser.flushInput()
        #self.ser.flushOutput()
        for id in idx:
            command = 'AT+CMGD=%s\r\n' % id
            self.SendCommand(command, 18)

    def getMsg(self, idx):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGR=%s\r\n' % idx
        self.ser.write(command)
        data = self.ser.readline()
        data += self.ser.readline()
        data3 = self.ser.readline()
        data = data + data3
        if "CMGR" in data3:
            data += self.ser.readline()
            data += self.ser.readline()
            data += self.ser.readline()
        return data

    def isRunning(self, pid):
        path = "/proc/" + str(pid)
        return os.path.exists(path)
コード例 #46
0
	def createSMS(self,num,msg,smsc,shahash):
		num=str(strip(num))
		msg=str(strip(msg))
		smsc=str(strip(smsc))
		### Log('createSMS new msg (0): NUM: '+num+", MSG: "+msg+", SMSC: "+smsc+", LEN:"+str(len(msg))+", HASH: "+shahash)
		if smsc[0] != "+" and smsc[0] != "0":
			smsc = "+"+smsc
		if num[0] != "0" and num[0] != "+":
			num = "+"+num
		Log('createSMS new msg (1): NUM: '+num+", MSG: "+msg+", SMSC: "+smsc+", LEN:"+str(len(msg))+", HASH: "+shahash)
		
		#reaplace unusual characters and white spaces
		msg=msg.replace("*","")
		msg=msg.replace("[","")
		msg=msg.replace("]","")
		msg=msg.replace("/","")
		msg=msg.replace("\\"," ")
		msg=msg.replace("\t"," ")
		msg=msg.replace("\n"," ")
		while True:
			if "  " in msg:
				msg=msg.replace("  "," ")
			else:
				break
		msg=strip(msg)
		if len(msg) > SMSLENGTH:
			Log('createSMS cutted msg: '+msg)
			msg=msg[0:SMSLENGTH]
		Log('	: NUM: '+num+", MSG:"+msg+", SMSC: "+smsc+", MSGLEN:"+str(len(msg))+", ID: "+shahash)
			
		if not USE_GSM_MODEM:
			
			#create sms format pdu
			y=strftime("%Y", gmtime())
			sms = SmsSubmit(num, msg)
			
			#validity= end of this year
			sms.validity = datetime(int(y)+1, 12, 31, 23, 59, 59)
			sms.csca = smsc
			pdu = sms.to_pdu()[0]
			
			s=pdu.pdu
			#print s
			
			##calculate checksum
			l=0
			sum=0
			for i in xrange(len(s)):
				if (i == 0 or i%2 == 0):
					j=i+2
					h= s[i:j]
					#print "hex:",h
					ih=int(h,16)
					#print "int:",str(ih)
					sum=(sum+ih) % 256
				l+=1
			fulllength=str((l/2)-8)
			chsum=str(hex(sum))[2:]
			#print "length: ",fulllength
			#print "sum: ",chsum

			tosend="AT^SM=32,"+fulllength+","+s+","+chsum
			#print "pdu:", tosend
			
			#try to send sms 5 times:
			Log('createSMS: SMS SENDING, BODY: '+str(tosend))
			msgsent=self.CommandSender(tosend,False,False,"smsout",20)
		else:
			if not len(self.GSMModules):
				Log("ERROR! No GSM module found! Message not sent.")
				return
			r=randint(0,(len(self.GSMModules)-1))
			usemod=str(self.GSMModules[r])
			
			self.initTelnetConnection()
			self.sendTelnetCommand("AT",False,False,'OK')
			self.sendTelnetCommand("AT!G=55",False,False,'OK')
			self.sendTelnetCommand("AT!G=A6",False,False,'OK')
			self.sendTelnetCommand("AT&G0"+usemod+"=AT+CMGF=1",False,False,'OK')
			#1
			tosend='AT&G0'+usemod+'=AT+CMGS="%s"' % num
			result=self.sendTelnetCommand(tosend,False,False,"++g00")
			Log("USE_GSM_MODEM, step1: ",result)
			#2
			tosend=msg+'\x1A'
			msgsent=self.sendTelnetCommand(tosend,False,False,"OK")
			Log("USE_GSM_MODEM, step2: ",msgsent)
			self.sendTelnetCommand("AT!G=55",False,False,'OK')
		
		#if not sent, put back to the queue:
		if not msgsent:
			Log('createSMS ERROR: cannot send SMS. Put back to INQ:'+str(msgsent))
			nowdate=str(strftime('%Y-%m-%d %H:%M:%S', localtime()))
			sqlobj=initSQLite(True)
			qry="UPDATE sms SET status = 'senderror', lastdate='"+nowdate+"'  WHERE hash = '"+shahash+"'"
			SQLiteExec(qry,sqlobj)
			SQLiteClose(sqlobj)
			###INQ.put_nowait([num,msg,smsc,shahash])
			sleep(1)
			return False
		
		#if sent: change status:
		else:
			nowdate=str(strftime('%Y-%m-%d %H:%M:%S', localtime()))
			sqlobj=initSQLite(True)
			qry="UPDATE sms SET status = 'sent', lastdate='"+nowdate+"'  WHERE hash = '"+shahash+"'"
			SQLiteExec(qry,sqlobj)
			SQLiteClose(sqlobj)
			Log('createSMS: SMS sent OK:'+str(msgsent))
			return True
コード例 #47
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
    def test_encoding_validity(self):
        # no validity
        number = '2b3334363136353835313139'.decode('hex')
        text = "hola"
        expected = "0001000B914316565811F9000004E8373B0C"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        # absolute validity
        number = '2b3334363136353835313139'.decode('hex')
        text = "hola"
        expected = "0019000B914316565811F900000170520251930004E8373B0C"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = datetime(2010, 7, 25, 20, 15, 39)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        # relative validity
        number = '2b3334363136353835313139'.decode('hex')
        text = "hola"
        expected = "0011000B914316565811F90000AA04E8373B0C"
        expected_len = 18

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
        self.assertEqual(pdu.length, expected_len)
コード例 #48
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
 def test_unicode_6(self):
     sms = SmsSubmit(self.DEST, self.UNICODE_CHAR * 67 * 3 + self.GSM_CHAR)
     self.assertEqual(len(sms.to_pdu()), 4)
コード例 #49
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
 def test_unicode_3(self):
     sms = SmsSubmit(self.DEST, self.UNICODE_CHAR * 67 * 2)
     self.assertEqual(len(sms.to_pdu()), 2)
コード例 #50
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
 def test_egsm_4(self):
     sms = SmsSubmit(self.DEST,
                     self.EGSM_CHAR * 229 + self.GSM_CHAR)  # 459 septets
     self.assertEqual(len(sms.to_pdu()), 4)
コード例 #51
0
ファイル: test_sms.py プロジェクト: IPv777/python-messaging
 def test_egsm_3(self):
     sms = SmsSubmit(self.DEST, self.EGSM_CHAR * 153)  # 306 septets
     self.assertEqual(len(sms.to_pdu()), 3)
コード例 #52
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
    def test_encoding_validity(self):
        # no validity
        number = "+34616585119"
        text = "hola"
        expected = "0001000B914316565811F9000004E8373B0C"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        # absolute validity
        number = "+34616585119"
        text = "hola"
        expected = "0019000B914316565811F900000170520251930004E8373B0C"

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = datetime(2010, 7, 25, 20, 15, 39)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)

        # relative validity
        number = "+34616585119"
        text = "hola"
        expected = "0011000B914316565811F90000AA04E8373B0C"
        expected_len = 18

        sms = SmsSubmit(number, text)
        sms.ref = 0x0
        sms.validity = timedelta(days=4)

        pdu = sms.to_pdu()[0]
        self.assertEqual(pdu.pdu, expected)
        self.assertEqual(pdu.length, expected_len)
コード例 #53
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
 def test_unicode_6(self):
     sms = SmsSubmit(self.DEST, self.UNICODE_CHAR * 67 * 3 + self.GSM_CHAR)
     self.assertEqual(len(sms.to_pdu()), 4)
コード例 #54
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
 def test_unicode_3(self):
     sms = SmsSubmit(self.DEST, self.UNICODE_CHAR * 67 * 2)
     self.assertEqual(len(sms.to_pdu()), 2)
コード例 #55
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
 def test_egsm_4(self):
     sms = SmsSubmit(self.DEST,
                       self.EGSM_CHAR * 229 + self.GSM_CHAR)  # 459 septets
     self.assertEqual(len(sms.to_pdu()), 4)
コード例 #56
0
ファイル: test_sms.py プロジェクト: bewest/python-messaging
 def test_egsm_3(self):
     sms = SmsSubmit(self.DEST, self.EGSM_CHAR * 153)  # 306 septets
     self.assertEqual(len(sms.to_pdu()), 3)
コード例 #57
0
	def createSMS(self,num,msg,smsc,shahash):
		num=str(strip(num))
		msg=str(strip(msg))
		smsc=str(strip(smsc))
		
		### Log('createSMS new msg (0): NUM: '+num+", MSG: "+msg+", SMSC: "+smsc+", LEN:"+str(len(msg))+", HASH: "+shahash)
		if smsc[0] != "+" and smsc[0] != "0":
			smsc = "+"+smsc
		if num[0] != "0" and num[0] != "+":
			num = "+"+num
		### Log('createSMS new msg (1): NUM: '+num+", MSG: "+msg+", SMSC: "+smsc+", LEN:"+str(len(msg))+", HASH: "+shahash)
		
		#reaplace unusual characters and white spaces
		msg=msg.replace("*","")
		msg=msg.replace("\t"," ")
		msg=msg.replace("\n"," ")
		while True:
			if "  " in msg:
				msg=msg.replace("  "," ")
			else:
				break
		msg=strip(msg)
		if len(msg) > SMSLENGTH:
			Log('createSMS cutted msg: '+msg)
			msg=msg[0:SMSLENGTH]
		Log('createSMS new msg: NUM: '+num+", MSG:"+msg+", SMSC: "+smsc+", MSGLEN:"+str(len(msg))+", ID: "+shahash)
		
		#create sms format pdu
		y=strftime("%Y", gmtime())
		sms = SmsSubmit(num, msg)
		
		#validity= end of this year
		sms.validity = datetime(int(y)+1, 12, 31, 23, 59, 59)
		sms.csca = smsc
		pdu = sms.to_pdu()[0]
		
		s=pdu.pdu
		#print s
		
		##calculate checksum
		l=0
		sum=0
		for i in xrange(len(s)):
			if (i == 0 or i%2 == 0):
				j=i+2
				h= s[i:j]
				#print "hex:",h
				ih=int(h,16)
				#print "int:",str(ih)
				sum=(sum+ih) % 256
			l+=1
		fulllength=str((l/2)-8)
		chsum=str(hex(sum))[2:]
		#print "length: ",fulllength
		#print "sum: ",chsum

		tosend="AT^SM=32,"+fulllength+","+s+","+chsum
		#print "pdu:", tosend
		
		#try to send sms 5 times:
		Log('createSMS: SMS SENDING, BODY: '+str(tosend))
		msgsent=self.CommandSender(tosend,False,False,"smsout",20)
		
		#if not sent, put back to the queue:
		if not msgsent:
			Log('createSMS ERROR: cannot send SMS. Put back to INQ:'+str(msgsent))
			nowdate=str(strftime('%Y-%m-%d %H:%M:%S', localtime()))
			sqlobj=initSQLite(True)
			qry="UPDATE sms SET status = 'senderror', lastdate='"+nowdate+"'  WHERE hash = '"+shahash+"'"
			SQLiteExec(qry,sqlobj)
			SQLiteClose(sqlobj)
			###INQ.put_nowait([num,msg,smsc,shahash])
			sleep(1)
			return False
		
		#if sent: change status:
		else:
			nowdate=str(strftime('%Y-%m-%d %H:%M:%S', localtime()))
			sqlobj=initSQLite(True)
			qry="UPDATE sms SET status = 'sent', lastdate='"+nowdate+"'  WHERE hash = '"+shahash+"'"
			SQLiteExec(qry,sqlobj)
			SQLiteClose(sqlobj)
			Log('createSMS: SMS sent OK:'+str(msgsent))
			return True
コード例 #58
0
ファイル: smspdu.py プロジェクト: awangga/spy
class Smspdu(object):
    def __init__(self, recipient=config.recipient, message=config.message):
        self.logfile = open("modem.log","w")
        self.open()
        self.recipient = recipient
        self.content = message
        

    def open(self):
        self.logfile.write(str(datetime.now()))
        self.logfile.write('open serial\n')
        self.ser = serial.Serial(config.serial, 115200, timeout=2.05)
        self.logfile.write(str(datetime.now()))
        self.logfile.write('send ATZ\n')
        self.SendCommand('ATZ\r')
        self.logfile.write(str(datetime.now()))
        self.logfile.write('send ATZ\n')
        self.SendCommand('AT+CMGF=0\r')

    def rcpt(self, number):
        self.recipient = number

    def msg(self, message):
        self.content = message

    def send(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        self.pdu = SmsSubmit(self.recipient, self.content)
        for xpdu in self.pdu.to_pdu():
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('send CMGS\n')
	        command = 'AT+CMGS=%d\r' % xpdu.length
	        self.SendCommand(command,getline=True)
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 1 CMGS\n')
	        data = self.ser.readall()
	        print data
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 2 CMGS\n')
	        command = '%s\x1a' % xpdu.pdu
	        self.SendCommand(command,getline=True)
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 3 CMGS\n')
	        data = self.ser.readall()
	        print data
	        self.logfile.write(str(datetime.now()))
	        self.logfile.write('after send 4 CMGS\n')

    def close(self):
        self.ser.close()

    def SendCommand(self,command, getline=True):
        self.ser.write(command)
        data = ''
        if getline:
            data=self.ReadLine()
        return data 

    def ReadLine(self):
        data = self.ser.readline()
        print data
        return data 

    def unread(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGL=0\r\n'#gets incoming sms that has not been read
        self.SendCommand(command,getline=True)
        data = self.ser.readall()
        print data
        
    def read(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGL=1\r\n'#gets incoming sms that has not been read
        self.SendCommand(command,getline=True)
        data = self.ser.readall()
        print data

    def all(self):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGL=4\r\n'#gets incoming sms that has not been read
        self.SendCommand(command,getline=True)
        data = self.ser.readall()
        print data
        
    def delete(self, idx):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGD=%s\r\n' % idx
        self.SendCommand(command,getline=True)
        data = self.ser.readall()
        print data

    def get(self, idx):
        self.ser.flushInput()
        self.ser.flushOutput()
        command = 'AT+CMGR=%s\r\n' % idx
        self.SendCommand(command,getline=True)
        data = self.ser.readall()
        print data