This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
forked from ZarvisD/way2sms
-
Notifications
You must be signed in to change notification settings - Fork 2
/
way2sms.py
71 lines (57 loc) · 2.24 KB
/
way2sms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import requests
import random
import time
import randomheader
def send_msg(jsession_id, msg, smsnumber):
toke = jsession_id[4:]
header = randomheader.header()
header.update({
'Host': 'site21.way2sms.com',
'Accept-Encoding': 'gzip, deflate, sdch',
'Referer': 'http://site21.way2sms.com/sendSMS?Token=' + toke,
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'})
cookie = dict(_ga='GA1.2.1259803070.1448989082', __gads='ID=2f1b44c88b3b95b7:T=1448989082:S=ALNI_MaipwWyw2hUU0fylEPb_gxGhuABig', JSESSIONID=jsession_id, _gat='1')
payload = {'ssaction': 'ss', 'Token': toke, 'mobile': smsnumber, 'message': msg, 'msgLen': len(msg)}
url1 = "http://site21.way2sms.com/smstoss.action"
r1 = requests.post(url1, headers=header, cookies=cookie, data=payload)
if r1.status_code == 200:
if ('finished your day quota' in str(r1.content)):
print('Message not sent. Day Quota is completed.')
return False
else:
print("Message sent to : %s \n" % (smsnumber))
return True
else:
print("Message not sent. Try after some time.")
return False
def send(Text, smsnumber):
# Way2Sms credentials
user_number = str(input("Please enter the username: + 91"))
password = str(input("Please enter the password: "))
url = "http://site21.way2sms.com/Login1.action"
# limit the character length
msg = (Text)[0:160]
payload = {
'username': user_number,
'password': password
}
session = requests.Session()
# Randomly sleep for some time ;)
time.sleep(random.uniform(1, 5))
try:
r = session.post(url, data=payload)
cj = session.cookies
# print (r.content.decode('ISO-8859-1').encode('utf8'))
session_id = requests.utils.dict_from_cookiejar(cj)
f_session_id = session_id['JSESSIONID']
rrr = f_session_id
_b = send_msg(rrr, msg, smsnumber)
if _b is True:
return True
elif _b is False:
return False
except Exception as e:
print('Message not sent. Error logging in to SMS vendor: \n', e)
return False
if __name__ == '__main__':
send('Test message from Way2Sms', '97812345678')