Author Topic: [Python] sms-tool.py  (Read 5235 times)

0 Members and 1 Guest are viewing this topic.

Offline frog

  • Knight
  • **
  • Posts: 232
  • Cookies: 16
    • View Profile
[Python] sms-tool.py
« on: December 12, 2012, 09:16:38 am »
I saw one of these using PHP somewhere in the forums. I thought I would make my own to see if I could. I know, my Python is terrible and there is a very dirty exception that I don't quite know how to handle that can be triggered by pressing enter at the first prompt for input. If anybody knows how to catch that exception properly please let me know. Anyways, here's the goods.

Code: (Python) [Select]
#!/usr/bin/env python
##
### sms-tool.py - messaging over the internet using sms gateways
##
#
import smtplib

emailAddr = "@gmail.com"
emailPasswd = ""
smtpServer = "smtp.gmail.com"

smsGateways = ["txt.att.net", # at&t
            "vtext.com", # verizon
            "vmobl.com", # virgin
            "cingular.com",    # cingular
            "sms.mycricket.com", # cricket
            "sms.edgewireless.com", # edge wireless
            "qwestmp.com", # qwest
            "messaging.sprintpcs.com", # sprint
            "page.nextel.com", # nextel
            "tmomail.net"] # t-mobile
           
providers = ["At&t", "Verizon", "Virgin Mobile", "Cingular",
                    "Cricket", "Edge Wireless", "Qwest", "Sprint",
                    "Nextel", "T-Mobile"]
           
def banner():
    print "    sms-tool.py - prototype sms bomber"   
    print "       by frog(frog5346@gmail.com)"
    print ""
   
def main():
    banner()
   
    for item in range(len(smsGateways)):
        print ("  " + str(item) + ": " + providers[item] + " (" +
               smsGateways[item]) + ")"
               
    print ""
    choice = raw_input("Choose provider: ")
   
    while int(choice) >= len(smsGateways):
        print "Invalid choice."
        choice = raw_input("Choose provider: ")
       
    if int(choice) < len(smsGateways):
        print "Provider: " + providers[int(choice)]
       
    phoneNum = raw_input("Enter number(area code first): ")
    print "Phone: " + str(phoneNum) + "@" + smsGateways[int(choice)]
   
    msg = raw_input("Now type your message: ")
    print ""
    print "To: " + str(phoneNum) + "@" + smsGateways[int(choice)]
    print "Message: " + msg
    print ""
   
    theCount = raw_input("How many times should we send the message? ")
    allCount = theCount
    print "Message will be sent " + theCount + " times."
    confirm = raw_input("Ready to send? ")
   
    if confirm == "y" or confirm == "Y" or confirm == "yes" or confirm == "Yes":
        destAddr = str(phoneNum) + "@" + smsGateways[int(choice)]
        connection = smtplib.SMTP(smtpServer)
        connection.set_debuglevel(1)
       
        try:
            connection.starttls()
            connection.login(emailAddr, emailPasswd)
        except smtplib.SMTPAuthenticationError, smtplib.SMTPException:
            print "SMTP Authentication error."
            exit()
       
        while theCount > 0:
            connection.sendmail(emailAddr, destAddr, msg)
            theCount = int(theCount) - 1
       
        print ""   
        print str(allCount) + " message(s) sent successfully."
       
    if confirm == "n" or confirm == "N" or confirm == "no" or confirm == "No":
        print "Aborted."
        exit()
             
if __name__ == "__main__":
    main()

Make sure to set your email address and password before running it. I recommend using a gmail account as it's the only one I've tested and know for a fact it works. Also if you want to add more providers/gateways just add an entry to each list(a server-name for the 'gateways' list and a proper-name for the 'providers' list).

Offline zWaR

  • Serf
  • *
  • Posts: 32
  • Cookies: 7
    • View Profile
Re: [Python] sms-tool.py
« Reply #1 on: December 25, 2012, 10:22:55 pm »
« Last Edit: January 04, 2013, 08:49:01 pm by zWaR »

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] sms-tool.py
« Reply #2 on: December 26, 2012, 04:43:33 am »
Some providers wont work. You just need to test them. I know Verizon doesn't like it and others will block it.

I have written several scripts to do this with bombing, automated messaging from sensors, reminders, etc... Just check that the carrier will accept these messages.
>>>import this
-----------------------------

Offline frog

  • Knight
  • **
  • Posts: 232
  • Cookies: 16
    • View Profile
Re: [Python] sms-tool.py
« Reply #3 on: December 26, 2012, 05:38:45 pm »
Yea, I found that if you send too many messages from the same IP that eventually you will be blacklisted(at least with at&t). I can't see why you couldn't send a couple messages here and there without interference; can you elaborate on which providers will not accept incoming messages? I haven't really had the time to test all of them; only a couple I know work for a fact(Sprint, Verizon, At&t).

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: [Python] sms-tool.py
« Reply #4 on: December 26, 2012, 06:53:46 pm »
Verizon and Ntelos never worked for me. The only others I've tested with are AT&T and Sprint which both seem to work okay.
>>>import this
-----------------------------

Offline frog

  • Knight
  • **
  • Posts: 232
  • Cookies: 16
    • View Profile
Re: [Python] sms-tool.py
« Reply #5 on: December 27, 2012, 03:09:55 pm »
I don't remember having any problems with verizon but, as far as I can tell there is a daily limit on messages sent based on email address through w/e smtp server you are using. In the case of gmail, this is a limitation of the gmail smtp server(it's customized to look for certain anomalies) as it's trying to keep the server load down. I would get my connection unexpectedly closed by the server(which I can reprogram my script the detect this and reconnect) after sending a few(cough) messages but eventually it will spit back a message any time I try to send a message which states 'daily transmission limit has been reached'.
« Last Edit: December 27, 2012, 03:10:52 pm by frog »