יום ראשון, דצמבר 15, 2013

משלוח קבצים ב MMS

נאלצתי לבצע העברת קבצים די גדולה לפני זמן מה וחבילת האינטרנט בנייד הסתיימה.
מכיוון שאני די תקוע עם linmodem ואין לי יכולת לפתוח קישור ע"ג gnuradio גמלה בלבי ההחלטה להשתמש בMMS בשביל לשלוח את הקבצים.

מה שעשיתי היה להתקין את python-messaging ולכתוב תסריט פשוט שיבצע שליחה של הקבצים.
בחרתי לשלוח ע"ג תמונה בגלל היכולת שלgif לאחסן קבצים אחרים ועדיין לעבור תחת הידיים של האנטיספאמרים הידועים לי.

תוצאות:

בדקתי עם מספר ספקים ושליחה של מ"ב ספורים (עד 3 לקובץ מקודד) עברה בצורה תקינה.

לא הייתי ממליץ לשלוח ג"ב בצורה כזאת (כי בכל זאת MMSים עולים כסף - אם אני מבין נכון זה נע באזור ה60 אגורות ליחידה) ואצל חלק מהמפעילים גודל ההודעות מתומכר גם כן.

תזהרו לא להספים או לשלוח לרשומות תפוצה (זה לא שימוש הוגן והספק כנראה ינתק אותכם).

דברים שצריך לדעת לפני :

הapn
הsmsc

התסריט עצמו:

#!/usr/bin/python
 

from messaging.mms.message import MMSMessage, MMSMessagePage

from argparse import RawTextHelpFormatter
import argparse

import socket    
import cStringIO # for the response

import sys,os #needed for file size + exit
import errno  #error handling
import getpass#to log the user name

parser = argparse.ArgumentParser(description='Send mms image to an email or a PSTN',formatter_class=RawTextHelpFormatter,
     epilog="""
 Scrapped from the docs by Boris Shtrasman (license GPLv2 as the python-messaging)

 1. In case you don't have a public access to mmsc (like I do): 

 get a cable and connect your phone to the pc,find out what are your mmsc and apn
 
 my mms apn is mms.provider.fr (look for mms apn configuration at your provider.tld)
 wvdial.conf example: 
    [Dialer mms]
    Phone = *99***1#
    Username = fillmeifneed #if your provider uses a username for mms fill it up
    Password = fillmeifneed #if your provider uses a password for mms fill it up
    Stupid Mode = 1
    Dial Command = ATDT
    Modem = /dev/ttyACM0
    Baud = 460800
    Init2 = ATZ
    Init3 = ATE0V1&D2&C1S0=0+IFC=2,2
    ISDN = 0
    Modem Type = Analog Modem
    Init5 =AT+CGDCONT=1,"IP","mms.provider.fr";
 
 run wvdial 
 ~/sudo screen wvdial mms
 
 You would need to check your routing as both the mms provider and your internet provider would\
 give you an ip address.
 
 2. 
 
 find out what is the mmsc address ,don't relay on name as some provider will not resolve it in my example it is 192.168.10.200
 every mms provider has it own port mine used 8080 (other use 80, 9090 and many others)

 In order to pass normal files zip them and add into a gif : 
    cat ~/somegif.gif >> /tmp/tobesent.gif
    zip -0 archive.zip stufftosend/* 
    cat ./archive >> /tmp/tobesent.gif
    
 to send to an email to user at example dot  net when your provider uses email  : 
    send -s 192.168.10.200 --port 8080 -i /tmp/tobesent.gif -d "user@example.net"  -a /mmsc -b "rename the gif to zip"
 to send an email to a phone number 
    send -s 192.168.10.200 --port 8080 -i /tmp/tobesent.gif -d "+3362123123"  -a /mmsc -b "rename the gif to zip" """)
     
     
parser.add_argument('-s','--mms_host', help='mmsc host',required=True)
parser.add_argument('-p','--port',help='mmsc port',type=int, required=True)
parser.add_argument('-i','--input_file',help='file to send as image', required=True)
parser.add_argument('-d','--destination',help='destination in PLMN or email', required=True)
parser.add_argument('-a','--mms_address',help='the mms address to use (commenly just /) some will have http://ip:port/path', required=True)
parser.add_argument('-c','--cc',help=' CC optional ', required=False)
parser.add_argument('-b','--subject',help=' subject  ', required=False)

args = parser.parse_args()

cc_destination = ''
if  args.cc: cc_destination = args.cc
subject = ''
if args.subject: subject=args.subject

print "As you wish %s, I will send the file:%s[%u kb] to %s and cc %s subject (%s)" % (getpass.getuser(),args.input_file,os.stat(args.input_file).st_size / 1024,args.destination,cc_destination,subject)
  
mms_page = MMSMessagePage()
mms_page.add_image(args.input_file)

mms = MMSMessage()
mms.headers['To'] = args.destination
mms.headers['Cc'] = cc_destination
mms.headers['Message-Type'] = 'm-send-req'
mms.headers['Subject'] = subject
mms.add_page(mms_page)
print "will encode '%s' (preparing what would be sent to the destination)" % args.input_file
encoded_mms = mms.encode()
print "message had been encoded"
mmsc_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print "connecting to %s:%u" % (args.mms_host , args.port)
try:
  mmsc_socket.connect((args.mms_host, args.port))
  
except socket.timeout:
  print "A timeout to %s:%d was set, make sure you can access it (routes, packet loss etc)" % (args.mms_host, args.port)
  sys.exit()
except KeyboardInterrupt:
  print "Don't be so hard on %s:%d it should work ... " % (args.mms_host, args.port)
  sys.exit()
except socket.error as serror:
  if serror.errno == errno.ECONNREFUSED:
    print "your provider prevent accessing to this mmsc %s have you checked you are using the correct credntials ?" %  (args.mms_host, args.port)
    sys.exit()
  if serror.errno == errno.ETIMEDOUT:
    print "I'm sorry but you need to check your routes to %s, then check your fw doesn't block unreachable destination, when all fail contact customer service" % (args.mms_host)
    sys.exit()

  print "A timeout to %s:%d was set, make sure you can access it (routes, packet loss etc) (%s)" % (args.mms_host, args.port, serror.errno)
  sys.exit()

  
print "was able to connect to %s:%u" % (args.mms_host , args.port)
mmsc_socket.send("POST %s HTTP/1.0\r\n" % args.mms_address)
print "POST command sent to the server"
mmsc_socket.send("Content-Type: application/vnd.wap.mms-message\r\n")
mmsc_socket.send("Content-Length: %d\r\n\r\n" % len(encoded_mms))
print "an encoded mms is on the way to the server , please wait : as %d bytes are on their way to the server and that will take some time" % len (encoded_mms)
try:
 mmsc_socket.sendall(encoded_mms)
except socket.error as serror:
  print "Try to use a smaller file, or check your connection as I couldn't finish the transfer %s" % serror.errno
  sys.exit()
except KeyboardInterrupt:
  mmsc_socket.close()
  print "Don't be so hard on %s:%d it should work ... " % (args.mms_host, args.port)
  sys.exit()
  
print "encoded mms had been sent "
serverResponseStream = cStringIO.StringIO()

while True:
    data = mmsc_socket.recv(4096)
    if not data:
        break

    serverResponseStream.write(data)

mmsc_socket.close()
data = serverResponseStream.getvalue()
serverResponseStream.close()

print "PROXY RESPONSE", data

אין תגובות:

הוסף רשומת תגובה