''' Created on 22-Jan-2013 @author: abhi ''' import httplib,urllib from urlparse import urlparse headers = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0','Referer': 'http://site3.way2sms.com/'} username = '7676580202' password = 'pianist' def open_way2sms_com(): conn = httplib.HTTPConnection("www.way2sms.com") conn.request("GET","/") res = conn.getresponse() location = res.getheader('location') return location def follow_redirection(url): k = urlparse(url) conn = httplib.HTTPConnection(k.netloc) conn.request("GET",'/') res = conn.getresponse() headers['Referer'] = url def open_prehome(url): k = urlparse(url) conn = httplib.HTTPConnection(k.netloc) conn.request("GET",'/content/prehome.jsp',None,headers) res = conn.getresponse() cookie = res.getheader('Set-Cookie','cookie') headers.update({'Cookie':cookie.split(';')[0]}) headers['Referer'] = 'http://'+k.netloc+'/content/prehome.jsp' def open_homepage(url): ''' GET /content/index.html HTTP/1.1 Host: site3.way2sms.com User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://site3.way2sms.com/content/prehome.jsp Cookie: JSESSIONID=A01~D7890988F6C7DC4BC7D88904D188A460.w801 Connection: keep-alive ''' k = urlparse(url) conn = httplib.HTTPConnection(k.netloc) conn.request("GET",'/content/index.html',None,headers) res = conn.getresponse() headers['Referer'] = 'http://'+k.netloc+'/content/index.html' def do_login(u,p,url): ''' POST /Login1.action HTTP/1.1 Host: site3.way2sms.com User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://site3.way2sms.com/content/index.html Cookie: JSESSIONID=A01~D7890988F6C7DC4BC7D88904D188A460.w801 Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 62 username=7676580202&password=pianist&userLogin=no&button=Login ''' paramsdict = {'username':u,'password':p,'userLogin':'no','button':'Login'} params = urllib.urlencode(paramsdict) k = urlparse(url) conn = httplib.HTTPConnection('127.0.0.1:8080') conn.request("POST",url+'Login1.action',params,headers) res = conn.getresponse() print res.msg print res.read() def direct_login(): ''' POST /Login1.action HTTP/1.1 Host: site3.way2sms.com User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Referer: http://site3.way2sms.com/content/index.html Connection: keep-alive Content-Type: application/x-www-form-urlencoded Content-Length: 62 ''' u = '7676580202' p = 'pianist' mheaders = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:18.0) Gecko/20100101 Firefox/18.0','Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8','Accept-Language': 'en-US,en;q=0.5','Accept-Encoding': 'gzip, deflate','Referer': 'http://site3.way2sms.com/content/index.html','Connection': 'keep-alive','Content-Type': 'application/x-www-form-urlencoded','Content-Length': 62} paramsdict = {'username':u,'password':p,'userLogin':'no','button':'Login'} params = urllib.urlencode(paramsdict) conn = httplib.HTTPConnection('127.0.0.1:8080') conn.request("POST",'http://site3.way2sms.com/Login1.action',params,mheaders) res = conn.getresponse() print res.msg print res.read() if __name__ == '__main__': #location = open_way2sms_com() #follow_redirection(location) #open_prehome(location) #open_homepage(location) #do_login(username,password,location) direct_login()
0 comments:
Post a Comment