from os import popen, system from urllib import urlencode from urllib2 import urlopen, Request import mechanize import cookielib from BeautifulSoup import BeautifulSoup import sys, getopt def sendsms(): #You will need to fill in field_from, field_contactno and field_msg" global field_from global field_contactno global field_msg field_counter = 150-len(field_msg) # Extract the JSessionID from the cookie by loading the below page URL_BASE='http://msgctr.m1.com.sg/guest/' set_cookie = urlopen(URL_BASE).headers.getheader("Set-Cookie") sess_id = set_cookie[set_cookie.index("=")+1:set_cookie.index(";")] # Construct headers dictionary using the JSESSIONID headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0) Gecko/20100101 Firefox/10.0', 'Host':'msgctr.m1.com.sg', 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language':'en-us,en;q=0.5', 'Accept-Encoding':'gzip,deflate', 'Accept-Charset':'ISO-8859-1,utf-8;q=0.7,*;q=0.7','Cookie':'JSESSIONID='+sess_id} # Extract the location for the captcha image text = (urlopen(Request(URL_BASE+"index.jsp",headers=headers)).read()) for line in text.split("\n"): if "/guest/captcha.jpg" in line: line = (line.replace(' Specify the sms message to be sent" print " -f Specify the sender's name" print " -t Specify the M1 mobile number" print "\nContact:" print "------------------------------" print "[Web] http://milo2012.wordpress.com" print "[Mail/Google+] keith.lee2012@gmail.com" print "[twitter] @keith55" def main(): global field_from global field_contactno global field_msg field_msg = None field_contactno = None field_from = None if len (sys.argv) < 6: printSyntax() sys.exit(1) else: try: opts, args = getopt.getopt (sys.argv[1:], "m:f:t:") except: printSyntax() sys.exit(1) for opt, arg in opts: if opt == '-m': field_msg= arg elif opt == '-f': field_from = arg elif opt == '-t': field_contactno = arg sendsms() if __name__ == "__main__": main()