DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Start Coding With Google Cloud Workstations
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Why I Started Using Dependency Injection in Python
  • Reinforcement Learning for AI Agent Development: Implementing Multi-Agent Systems

Trending

  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • Artificial Intelligence, Real Consequences: Balancing Good vs Evil AI [Infographic]
  • AI's Dilemma: When to Retrain and When to Unlearn?
  1. DZone
  2. Coding
  3. Languages
  4. Python Script For Sending Free Sms Using Way2sms.com

Python Script For Sending Free Sms Using Way2sms.com

By 
Snippets Manager user avatar
Snippets Manager
·
Apr. 04, 10 · Code Snippet
Likes (1)
Comment
Save
Tweet
Share
15.7K Views

Join the DZone community and get the full member experience.

Join For Free

#!/usr/bin/python

__author__ = """
NAME: Abhijeet Rastogi (shadyabhi)
Profile: http://www.google.com/profiles/abhijeet.1989
"""

import cookielib
import urllib2
from getpass import getpass
import sys
from urllib import urlencode
from getopt import getopt

username = None
passwd = None
message = None
number = None

def Usage():
print '\t-h, --help:  View help'
print '\t-u, --username: Username'
print '\t-p, --password: Password'
print '\t-n, --number: numbber to send the sms'
print '\t-m, --message: Message to send'
sys.exit(1)


opts, args = getopt(sys.argv[1:], 'u:p:m:n:h',["username=","password=","message=","number=","help"])

for o,v in opts:
if o in ("-h", "--help"):
Usage()
elif o in ("-u", "--username"):
username = v
ask_username = False
elif o in ("-p", "--password"):
passwd = v
ask_password = False
elif o in ("-m", "--message"):
message = v
ask_message = False
elif o in ("-n", "--number"):
number = v
ask_number = False

#Credentials taken here
if username is None: username = raw_input("Enter USERNAME: ")
if passwd is None: passwd = getpass()
if message is None: message = raw_input("Enter Message: ")
if number is None: number = raw_input("Enter Mobile number: ")

#Logging into the SMS Site
url = 'http://wwwb.way2sms.com//auth.cl'
data = 'username='+username+'&password='+passwd+'&Submit=Sign+in'

#Remember, Cookies are to be handled
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))

# To fool way2sms as if a Web browser is visiting the site
opener.addheaders = [('User-Agent','Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.5.3 GTB7.0')]
try:
usock = opener.open(url, data)
except IOError:
print "Check your internet connection"
sys.exit(1)

#urlencode performed.. Because it was done by the site as i checked through HTTP headers

message = urlencode({'message':message})
message = message[message.find("=")+1:]

#SMS sending
send_sms_url = 'http://wwwb.way2sms.com//FirstServletsms?custid='
send_sms_data = 'custid=undefined&HiddenAction=instantsms&Action=custfrom950000&login=&pass=&MobNo='+number+'&textArea='+message
opener.addheaders = [('Referer','http://wwwb.way2sms.com//jsp/InstantSMS.jsp?val=0')]

try:
sms_sent_page = opener.open(send_sms_url,send_sms_data)
except IOError:
print "Check your internet connection( while sending sms)"
sys.exit(1)
print "SMS sent!!!"


Python (language)

Opinions expressed by DZone contributors are their own.

Related

  • Start Coding With Google Cloud Workstations
  • Beyond ChatGPT, AI Reasoning 2.0: Engineering AI Models With Human-Like Reasoning
  • Why I Started Using Dependency Injection in Python
  • Reinforcement Learning for AI Agent Development: Implementing Multi-Agent Systems

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: