Script Request: Send free SMS Text Messages from XBMC - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33) +--- Forum: Add-on Support (https://forum.kodi.tv/forumdisplay.php?fid=27) +--- Thread: Script Request: Send free SMS Text Messages from XBMC (/showthread.php?tid=28433) |
Script Request: Send free SMS Text Messages from XBMC - kaisersose - 2005-05-02 hi, im just enquring if anyone knows if it is possible to use python scripts for sites that seem to use jsp's. the sites i am on about are the o2 and vodafone irish(.ie) and uk(.co.uk) sites and their free online txt messages. i just thought id ask here as i think it would be cool to able 2 send txt messages from the xbox when u run out of credit. anyways, if anyone uses them sites and knows about python id appreciate if they'd let me know, and i'll try it if its possible when i get my exams over with. cheers - kaisersose - 2005-05-02 after a bit of googling i found this python code from egenix.com, they dont mention what free sms sites this can be used for so if anyone knows please reply. i cant check this out as im using xdsl atm, but hopefully its of use 2 someone. #!/usr/local/bin/python """ sms mailer. this module allows sending sms messages using one of the available free sms mailer web-sites. copyright © 2000, marc-andre lemburg ([email protected]). all rights reserved. *** for private use only ! *** permission to use, copy, modify, and distribute this software and its documentation for any private, non-commercial purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make. before sending sms messages using this module, you must make sure that you are in accord and accept the usage conditions and limitations set forth by the sms message service of your choice. some message services disallow usage of techniques applied in this module. if this is the case, you are not allowed to use the module for sending sms messages via these services. usage of this software is at your own risk. the author marc-andre lemburg disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness, in no event shall the author be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software ! """#" import urllib, string # version number = '0.1' ### changelog # # 0.1 - initial release # # enable debugging output ? = 0 class smsmailer: """ base class for sms mailers. the base class does not provide a usable sms mailer. you have to subclass this class in order to specify the different options. """ # url which provides the service url = '' # form action method to use ('post' or get') method = 'post' # static cookie to send cookie = '' # if set, .cookie will be set by first querying a cookie from the # following url cookieurl = '' # max. size of a single message maxsize = 120 # user agent string to send agent = 'mozilla/4.7 [en] (win98; u)' def format_params(self, params, quote=urllib.quote,join=string.join, strip=string.strip): l = [] for k,v in params.items(): k = strip(str(k)) v = str(v) l.append('%s=%s' % (quote(k), quote(v))) return join(l, '&') def get_cookie(self): if not self.cookieurl: return self.cookie wget = urllib.fancyurlopener() f = wget.open(self.cookieurl) try: cookie = f.headers.dict['set-cookie'] except keyerror: cookie = self.cookie else: cookie = string.split(cookie, ';', 1)[0] f.close() return cookie def encode(self, message, network, phone, idd): params = {} params['idd'] = idd params['network'] = network params['phone'] = phone params['message'] = message return params def format_message(self, message, join=string.join): l = [] while message: l.append(message[:16]) message = message[16:] if not l: raise valueerror, 'empty message' if len(l[-1]) < 16: l[-1] = l[-1] + '.'*(16 - len(l[-1])) l.append('-' * 16) text = join(l, '') if len(text) > self.maxsize: raise valueerror, \ 'message too long: max length = %i' % \ self.maxsize return text def send(self, message, network, phone, idd='49'): # check parameters message = str(message) phone = str(phone) network = str(network) idd = str(idd) if not phone: raise valueerror, 'missing phone number' if not network: raise valueerror, 'missing network number' if not message: raise valueerror, 'empty message' # format message message = self.format_message(message) # get cookie cookie = self.get_cookie() if : print 'using cookie',cookie # format and send data params = self.encode(message, network, phone, idd) data = self.format_params(params) wget = urllib.fancyurlopener() #wget = urllib.urlopener() wget.addheaders = [('user-agent', self.agent)] wget.addheaders.append(('cookie', cookie)) if self.method == 'post': connection = wget.open(self.url, data) else: connection = wget.open(self.url + '?' + data) reply = connection.read() connection.close() # check reply return self.check_reply(reply) def check_reply(self, reply): return 1 ### subclasses for different free mailers # # example for a smsmailer subclass. # # you will have to adapt this class to the free sms message provider # you intend to use. please read the provider's usage conditions # carefully -- not all services will allow these techniques to be # used. # class mysmsmailer(smsmailer): """ http://www.<my-sms-mailer>.com/ tested. fast and reliable. limitation: max. 5 sms / day to one phone from one ip address. """ # url which provides the service url = 'http://www.<my-sms-mailer>.com/sms/send.php3' # where to get the cookie from... cookieurl = ('http://www.<my-sms-mailer>.com/sms/send.php3?' 'action=accept') def encode(self, message, network, phone, idd): params = {} params['action'] = 'send' params['othernetwork'] = 'yes' params['networkkey'] = '' while network[0] == '0': network = network[1:] while idd[0] == '+': idd = idd[1:] params['number'] = '+%s %s %s' % (idd, network, phone) params['message'] = message params['send'] = 'send message!' return params def check_reply(self, reply): if string.find(reply, 'successful') >= 0: return 1 if : print 'failed to send message:' print reply return 0 ### testing if == '': # create smsmailer instance sms = mysmsmailer() # get data print 'send an sms to' idd = raw_input( ' access code [+49]: ') or '+49' network = raw_input(' network number : ') phone = raw_input( ' phone number : ') print 'message (one line only):' message = raw_input() # send message if sms.send(message, network, phone, idd): print 'message sent.' else: print 'failed to send message.' this site has a few links to various programs for sending sms: http://tuxmobil.org/phones_linux_sms.html and one of them is a perl script for sending txt messages through http://www.o2online.de, i know perl is no use but the o2 german site is probably the same as the uk and irish, so does anyone know if its possible with perl would it be possible with python? heres the code anyways: #!/usr/bin/perl ################################################################ # # o2-sms.pl, v2.0beta # # copyright © 2002-04 leonhard fellermayr # all rights reserved. # ################################################################ # -------------- used packages use strict; use uri::escape; use lwp::useragent; use http::request::common; use http::cookies; # --------------- your login data at o2 - please set my $o2_vorwahl = '0179'; my $o2_nummer = '1234567'; my $o2_kennwort = 'lesssssecret'; # --------------- urls of o2 online interface my $base_url = 'http://web2sms.o2online.de/'; my $login_url = 'https://login.o2online.de/login/pa/jsp/login.jsp'; my $login_referrer = $login_url . '?scheme=http&server=web2sms.o2online.de&port=80& \ url=/web2sms/jsp/default.jsp'; my $sms_main_url = $base_url . 'web2sms/jsp/default.jsp'; my $sms_post_url = $sms_main_url . '?check=1'; my $sms_main2_url = $base_url . 'web2sms/jsp/result1.jsp'; my $sms_post2_url = $base_url . 'web2sms/jsp/result2.jsp'; my $text_maxlen = 780; # max length when sending to other cellphones my $text_maxlen_wired = 160; # max length when doing "text-to-speech" # known german cellphone prefixes (everything else is assumed "wired") my @mobileprefixes = qw ('0179','0176','0160','0162','0163','0170','0171','0172','0173', \ '0174','0175','0177','0178','01505','01511','01520','01566','0151'); # --------------- fake one of these user agents via rand() call below my %agents = ( 0 => 'mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)', 1 => 'mozilla/4.0 (compatible; msie 5.0; windows 98; digext)', 2 => 'mozilla/5.0 galeon/1.2.5 (x11; linux i686; u gecko/20020606', 3 =>> 'mozilla/4.0 (compatible; msie 5.0; windows 2000) opera 6.04 [en]', 4 => 'mozilla/4.0 (compatible; msie 5.5; windows 98; win 9x 4.90)', 5 => 'mozilla/5.0 (windows; u; windows nt 5.1; de-de; rv:1.7b) gecko/20040421', 6 => 'mozilla 4.0 (compatible; msie 5.01; windows nt 5.0)', 7 => 'mozilla/4.0 (compatible; msie 6.0; windows 98)', 8 => 'mozilla/4.0 (compatible; msie 5.5; windows nt 4.0; lvr)', 9> 'mozilla/4.0 (compatible; msie 5.01; windows nt 5.0)', 10 => 'mozilla/5.0 (x11; u; linux i586; en-us; rv:1.1b) gecko/20020722' ); # --------------- get command line arguments if ($#argv < 0) { &syntax (); exit (0); } my $send_flash = ''; if ($argv[0] =~ /-f/) { $send_flash = 'on'; shift (@argv); } my $send_prefix = $argv[0]; my $send_number = $argv[1]; shift (@argv); shift (@argv); my $send_messagetext = join (" ", @argv); # --------------- check if this message goes to wired network my $wired = 0; foreach (@mobileprefixes) { $wired = 1 if ($_ == $send_prefix); } # --------------- perform some checks on given data if (($wired) && (length($send_messagetext)) > $text_maxlen_wired) { raiseerr (1, 'message goes as message-to-speech to wired network - message text \ only can have up to ' . $text_maxlen_wired . ' chars.'); } elsif (length ($send_messagetext) > $text_maxlen) { raiseerr (2, 'message text is too long - can have up to ' . $text_maxlen . ' chars.'); } elsif ($send_prefix =~ /^[^0]/) { raiseerr (3, 'prefix must start with 0.'); } elsif ($send_prefix =~ /^\d0/) { raiseerr (4, 'only can send nationally.'); } elsif ((length($send_prefix) < 3) || (length($send_prefix) > 5)) { raiseerr (5, 'please enter a prefix between 3 and 5 digits.'); } elsif ((length($send_number) < 4) || (length($send_number) > 12)) { raiseerr (6, 'please enter a number between 4 and 12 digits.'), } elsif ($send_prefix =~ /[^0-9]/) { raiseerr (7, 'prefix may contain only digits.'); } elsif ($send_number =~ /[^0-9]/) { raiseerr (8, 'number may contain only digits.'); } # --------------- set up a new user agent object my $ua = new lwp::useragent; my $response; # --------------- fake a real user agent my $max = -1; $max++ foreach (keys %agents); $ua->agent ($agents{int (rand ($max))}); # --------------- enable cookie transport my $cookies = new http::cookies; $ua->cookie_jar ($cookies); # --------------- 1. get base url $response = $ua->request (get $base_url); # --------------- 2. post login data $response = $ua->post ( $login_url, [ 'vorwahl' => $o2_vorwahl, 'pin_fld_login' => $o2_nummer, 'pin_fld_passwd_clear' => $o2_kennwort, 'appl' => 'web2sms.o2online.de', 'login' => 'login', 'hid' => '07' ], ); # --------------- 3. go to sms main page (meta redir) $response = $ua->request (get $sms_main_url); # --------------- 4. post sms data my $response = $ua->post ( $sms_post_url, [ 'prefix' => $send_prefix, 'msisdn' => $send_number, 'messagetext' => $send_messagetext, 'anzahl' => length ($send_messagetext), 'flash' => $send_flash, 'phonebook' => '', 'friendlyname' => '' ], ); # --------------- 5. get agb confirmation page $response = $ua->request (get $sms_main2_url); # --------------- 6. post confirmation $response = $ua->post ($sms_post2_url); ######################################################################################## sub syntax () { print<<eot; syntax: o2-sms.pl [-f] <prefix> <number> <message text> this script is intended for customers of o2 germany that have an account at http://www.o2online.de. these are able to send sms via the www gateway at less cost. o2-sms.pl brings this service down to your unix shell. use -f option to send flash sms (will pop up on the recipient's display immediately). message text can have up to 780 chars. note: sms to wired recipients are limited to 160 chars, as they are being sent as "text-to-speech". eot } sub raiseerr ($$ { my $exitno = shift; my $errtext = shift; &syntax (); print "error: $errtext\n\n"; exit ($exitno); and finally this site has a few things as well: http://www.keyvan.net/2004/11/16/sms-web-sender/ } - kaisersose - 2005-05-02 a few other programs for sending sms: http://unfunf.co.uk/o2sms/ http://www.mackers.com/projects/o2sms/ - robsta - 2005-05-04 this actually very easy to achieve using the curl program. i have successfully achieved this in php & perl with the correct bindings to curllib. there are python bindings available as well. curl homepage Script Request: Send free SMS Text Messages from XBMC - bladeuk - 2007-09-09 Hi, I've just bought (Not installed myself) an XBMC and wow it is much better than I could ever have dreamed of! A big thank you to everyone developing all the great scripts out there. I was wondering if it was possible for some to write a script that lets you send free SMS Text messages using the website Cardboad Fish (http://www.cbfsms.com/)? Thanks in advance! Sending free sms messages from XBMC - Bigfoot87 - 2007-09-20 Wouldn't it be nice it be nice to create a script that allows you to send sms messages using Callwave or another program or website? - dafunks - 2007-09-21 This is a great idea. Hope something comes from it - dan_f14 - 2007-09-22 I completely agree. It would be an awesome script. Could I add as a further idea the ability to create user profiles. All that would be needed is two fields, the name eg Dan, and the number eg 079xxxxxxxx. Then that could be added to the end of the message like a signature is added to the end of an email before it is sent. That way the recipients of the message will know who it is from and can reply to the individuals phone instead of replying to the free message and it being put on some server or whatever. - aronsmit - 2010-08-11 Simple and easy for modification, PHP script for SMS sending through HTTP http://sourceforge.net/projects/send-sms-script/ |