How to Send SMS Messages with Python « Null Byte :: WonderHowTo

In this article, I'll show you how to send SMS messages with Python. You'll need Python 2.7 or later, urllib and urllib2. The code basically uses an online text messaging service to "POST" html data, as if a person was entering the data themselves. The uses for something like this are unlimited. For example, I modified the basic code so I would receive a text message letting me know every time someone rang my doorbell. The program could interface with Arduino through a serial port, and send data to Python, which in turn forwards it to your phone. Or you could even use the program to notify you when you receive an email. Check outthisarticle on how to make a python Gmail notifier.The CodeThe first part of the code (provider check) takes the first six digits of the entered phone number and checks for the provider, then associates it with the correct "POST" command. The second part (text sender) takes the full phone number and message, and sends it to the online texting site.import urllibimport urllib2number = raw_input("Please Enter The Phone Number:\n")message = raw_input("Please Enter Your Message:\n")prov = ''url2 = 'http://www.txt2day.com/lookup.php'url = 'http://www.onlinetextmessage.com/send.php'values2 = {'action' : 'lookup','pre' : number[0:3],'ex' : number[3:6],'myButton' : 'Find Provider'}data2 = urllib.urlencode(values2)  ##provider checkerreq2 = urllib2.Request(url2, data2)response2 = urllib2.urlopen(req2)the_page2 = response2.read()if 'Telus' in the_page2:prov = '192'if 'Bell' in the_page2:prov = '48'if 'Rogers' in the_page2:prov = '162'if 'Sprint' in the_page2:prov = '175'if 'T-Mobile' in the_page2:prov = '182'if 'Verizon' in the_page2:prov = '203'if 'Virgin Mobile' in the_page2:prov = '205'if 'AT&T' in the_page2:prov = '41'print provif prov == 0:print "Failed To Identify Provider\n"exitvalues = {'code' : '','number' : number,'from' : '','remember' : 'n','subject' : '','carrier' : prov,'quicktext' : '','message' : message,'s' : 'Send Message'}data = urllib.urlencode(values)  ##text senderreq = urllib2.Request(url, data)response = urllib2.urlopen(req)the_page = response.read()Possible ModsIf the code fails to find your provider, enter the numberhere, and look for the associated number code to your cell phone providerhere. Insert an "if 'YourCellPhoneProvider' in the_page2: prov = 'AssociatedNumber'". If you'd like to use another online text messaging service, use Firebug to identify the form parameters, and change the "values" variables to the POST values. Enjoy! :)Want to start making money as a white hat hacker?Jump-start your hacking career with our2020 Premium Ethical Hacking Certification Training Bundlefrom the newNull Byte Shopand get over 60 hours of training from cybersecurity professionals.Buy Now (90% off) >Other worthwhile deals to check out:97% off The Ultimate 2021 White Hat Hacker Certification Bundle99% off The 2021 All-in-One Data Scientist Mega Bundle98% off The 2021 Premium Learn To Code Certification Bundle62% off MindMaster Mind Mapping Software: Perpetual LicenseRelatedHow To:Fix Delayed iMessages & Text Messages After Upgrading to iOS 7How To:Send & Receive Text Messages Right from Your Nexus 7 3G Tablet (Rooted & Non-Rooted)Anonymous Texting 101:How to Block Your Cell Phone Number While Sending Text MessagesHow To:Keep Long Texts from Breaking into Separate Messages on AndroidNews:Comparing the Best International Data Plans from All Major US CarriersNews:Google to Remove SMS Features from Hangouts (Update: New Version Rolling Out)How To:Send & Receive SMS Texts on Your Computer for FreeHow To:Send & Receive Encrypted Android Texts Using Your Mac's Messages AppHow To:Remotely View & Send Text Messages from Your Android Phone Using Any Web BrowseriPhone Text Bomb Your Friends:The Ultimate SMS PrankHow To:No Data, No Problem—Use SMS to Connect to Your Favorite Web Services on AndroidNews:Facebook Messenger Can Now Send & Receive All Your Texts—Here's How to Turn It OnNews:Hacker Points Out iOS Security Flaw That Allows iPhone Text SpoofingHow To:Use Gmail's New Confidential Mode to Send Private, Self-Destructing Emails from Your PhoneHow To:Let Friends & Family Know Where You Are Automatically with a Secret Text CodeHow To:Make an SMS Intruder AlarmHow To:TextStats Gives You Detailed Info of Your Text Messaging Habits on AndroidThe Hacks of Mr. Robot:How to Send a Spoofed SMS Text MessageHow To:Send Text SMS from Gmail AccountHow To:Find Your HTC One or Other Android Phone with a Text MessageHow To:Filter Unknown Senders in iMessage to Block Unwanted Notifications & Keep Your Messages App CleanHow To:iOS 12 Makes 2FA for Third-Party Apps & Websites Easy with Security Code AutoFill from SMS TextsHow To:Get Missed Calls & Contact Numbers from Your Phone—Without Having Your PhoneHow To:Add a contact to an SMS text message on a BlackBerry phoneHow To:Send Text Messages from Google Home to Any ContactHow To:Block Any Unwanted Text Messages or iMessages on Your iPhone in iOS 7How To:Send & Receive Texts from Your Android Using Apple Messages on Your MacHow To:Bypass Two-Way Authentication on Facebook with Android ScriptHow To:Be More Secretive Using Hide SMS and Call RecorderHow To:Prank Your Apple Friends with 1,000s of iMessages in Just One ClickHow To:Reply to Messages While You're Busy with SMS Replier for AndroidVenmo 101:How to Send Money Using the Messages App on Your iPhoneHow To:Encrypt Your Calls & Texts on AndroidHow To:10 Free Texting Apps for Android That Are Way Better Than Your Stock SMS AppHow To:Code a Basic TCP/IP Client & Server Duo in PythonHow To:Make a Gmail Notifier in PythonHow To:Filter Unwanted Calls & SMS for Free with Google VoiceWeekend Homework:How to Become a Null Byte Contributor (1/29/2012)How To:Encrypt And Decrypt Text In PythonWeekend Homework:How to Become a Null Byte Contributor (1/12/2012)