Difference between revisions of "Auth.py"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) (New page: =Script= <pre> #!/usr/bin/env python import sys import httplib import urllib #--------------------------------------------------------------------- class Error: pass def __init_...) |
PeterHarding (talk | contribs) |
||
(8 intermediate revisions by the same user not shown) | |||
Line 51: | Line 51: | ||
headers = { | headers = { | ||
'Referer' : 'http:// | 'Referer' : 'http://xxx.xxx.com.au/toll/authentication/Login.jsp', | ||
'Connection' : 'Keep-Alive', | 'Connection' : 'Keep-Alive', | ||
'User-Agent' : 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)', | 'User-Agent' : 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)', | ||
'Host' : ' | 'Host' : 'xxx.xxx.com.au', | ||
'Accept' : 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*', | 'Accept' : 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*', | ||
'Accept-Language' : 'en', | 'Accept-Language' : 'en', | ||
Line 66: | Line 66: | ||
'redir' : '/servlets/glog.webserver.util.FrameGC3Servlet', | 'redir' : '/servlets/glog.webserver.util.FrameGC3Servlet', | ||
'namespace' : 'GC3', | 'namespace' : 'GC3', | ||
'username' : 'MTS. | 'username' : 'MTS.XXX', | ||
'password' : ' | 'password' : 'xxx', | ||
'Log In.x' : '7', | 'Log In.x' : '7', | ||
'Log In.y' : '7' | 'Log In.y' : '7' | ||
Line 76: | Line 76: | ||
#--------------------------------------------------------------------- | #--------------------------------------------------------------------- | ||
data = 'redir=%2Fservlets%2Fglog.webserver.util.FrameGC3Servlet&namespace=GC3&username=MTS. | data = 'redir=%2Fservlets%2Fglog.webserver.util.FrameGC3Servlet&namespace=GC3&username=MTS.XXX&password=xxx&Log+In.x=7&Log+In.y=7' | ||
conn = httplib.HTTPConnection(" | conn = httplib.HTTPConnection("xxx.xxx.com.au") | ||
conn.putrequest('POST', '/ | conn.putrequest('POST', '/xxx/authentication/Login.jsp') | ||
conn.putheader('Referer', 'http:// | conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') | ||
conn.putheader('Connection', 'Keep-Alive') | conn.putheader('Connection', 'Keep-Alive') | ||
conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | ||
conn.putheader('Host', ' | conn.putheader('Host', 'xxx.xxx.com.au') | ||
conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | ||
conn.putheader('Accept-Language', 'en') | conn.putheader('Accept-Language', 'en') | ||
conn.putheader('Accept-Charset', 'iso-8859-1,*,utf-8') | conn.putheader('Accept-Charset', 'iso-8859-1,*,utf-8') | ||
conn.putheader('Cookie', 'JSESSIONID= | conn.putheader('Cookie', 'JSESSIONID=xxx') | ||
conn.putheader('Content-type', 'application/x-www-form-urlencoded') | conn.putheader('Content-type', 'application/x-www-form-urlencoded') | ||
conn.putheader('Content-length', '%d' % len(data)) | conn.putheader('Content-length', '%d' % len(data)) | ||
Line 114: | Line 113: | ||
#--------------------------------------------------------------------- | #--------------------------------------------------------------------- | ||
# conn = httplib.HTTPConnection(" | # conn = httplib.HTTPConnection("xxx.xxx.com.au") | ||
conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=GC3&username=MTS. | conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=GC3&username=MTS.XXX&userpassword=xxx") | ||
conn.putheader('Referer', 'http:// | conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') | ||
conn.putheader('Connection', 'Keep-Alive') | conn.putheader('Connection', 'Keep-Alive') | ||
conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | ||
conn.putheader('Host', ' | conn.putheader('Host', 'xxx.xxx.com.au') | ||
conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | ||
conn.putheader('Accept-Language', 'en') | conn.putheader('Accept-Language', 'en') | ||
Line 136: | Line 135: | ||
#--------------------------------------------------------------------- | #--------------------------------------------------------------------- | ||
conn = httplib.HTTPConnection(" | conn = httplib.HTTPConnection("xxx.xxx.com.au") | ||
conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=Default&username=MTS. | conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=Default&username=MTS.XXX&userpassword=xxx") | ||
conn.putheader('Referer', 'http:// | conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') | ||
conn.putheader('Connection', 'Keep-Alive') | conn.putheader('Connection', 'Keep-Alive') | ||
conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | ||
conn.putheader('Host', ' | conn.putheader('Host', 'xxx.xxx.com.au') | ||
conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | ||
conn.putheader('Accept-Language', 'en') | conn.putheader('Accept-Language', 'en') | ||
Line 158: | Line 157: | ||
#--------------------------------------------------------------------- | #--------------------------------------------------------------------- | ||
conn = httplib.HTTPConnection(" | conn = httplib.HTTPConnection("xxx.xxx.com.au") | ||
conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=Default&username=MTS. | conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=Default&username=MTS.XXX&userpassword=xxx") | ||
conn.putheader('Referer', 'http:// | conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') | ||
conn.putheader('Connection', 'Keep-Alive') | conn.putheader('Connection', 'Keep-Alive') | ||
conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') | ||
conn.putheader('Host', ' | conn.putheader('Host', 'xxx.xxx.com.au') | ||
conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') | ||
conn.putheader('Accept-Language', 'en') | conn.putheader('Accept-Language', 'en') | ||
Line 190: | Line 189: | ||
[[Category:Python]] | [[Category:Python]] | ||
[[Category:Python httplib]] | |||
[[Category:Python urllib]] | |||
[[Category:Examples]] | [[Category:Examples]] |
Latest revision as of 15:02, 1 August 2015
Script
#!/usr/bin/env python import sys import httplib import urllib #--------------------------------------------------------------------- class Error: pass def __init__(self, url, errcode, errmsg, headers): self.url = url self.errcode = errcode self.errmsg = errmsg self.headers = headers def __repr__(self): return ( "<Error for %s: %s %s>" % (self.url, self.errcode, self.errmsg) ) #--------------------------------------------------------------------- class Server: pass def __init__(self, host): self.Host = host def fetch(self, path): http = httplib.HTTP(self.Host) # write stuff... errcode, errmsg, headers = http.getreply() if errcode != 200: raise Error(errcode, errmsg, headers) file = http.getfile() return file.read() #--------------------------------------------------------------------- headers = { 'Referer' : 'http://xxx.xxx.com.au/toll/authentication/Login.jsp', 'Connection' : 'Keep-Alive', 'User-Agent' : 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)', 'Host' : 'xxx.xxx.com.au', 'Accept' : 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*', 'Accept-Language' : 'en', 'Accept-Charset' : 'iso-8859-1,*,utf-8' } # "Content-type" : "application/x-www-form-urlencoded", # "Accept" : "text/plain" params = urllib.urlencode({ 'redir' : '/servlets/glog.webserver.util.FrameGC3Servlet', 'namespace' : 'GC3', 'username' : 'MTS.XXX', 'password' : 'xxx', 'Log In.x' : '7', 'Log In.y' : '7' }) # print params #--------------------------------------------------------------------- data = 'redir=%2Fservlets%2Fglog.webserver.util.FrameGC3Servlet&namespace=GC3&username=MTS.XXX&password=xxx&Log+In.x=7&Log+In.y=7' conn = httplib.HTTPConnection("xxx.xxx.com.au") conn.putrequest('POST', '/xxx/authentication/Login.jsp') conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') conn.putheader('Connection', 'Keep-Alive') conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') conn.putheader('Host', 'xxx.xxx.com.au') conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') conn.putheader('Accept-Language', 'en') conn.putheader('Accept-Charset', 'iso-8859-1,*,utf-8') conn.putheader('Cookie', 'JSESSIONID=xxx') conn.putheader('Content-type', 'application/x-www-form-urlencoded') conn.putheader('Content-length', '%d' % len(data)) conn.endheaders() conn.send(data) print len(data) # errcode, errmsg, headers = conn.getreply() # if errcode != 200: # raise Error(errcode, errmsg, headers) # file = http.getfile() # return file.read() response = conn.getresponse() data = response.read() print "Status %s Reason \"%s\"" % (response.status, response.reason) print "Data \"%s\"" % data # conn.close() #--------------------------------------------------------------------- # conn = httplib.HTTPConnection("xxx.xxx.com.au") conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=GC3&username=MTS.XXX&userpassword=xxx") conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') conn.putheader('Connection', 'Keep-Alive') conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') conn.putheader('Host', 'xxx.xxx.com.au') conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') conn.putheader('Accept-Language', 'en') conn.putheader('Accept-Charset', 'iso-8859-1,*,utf-8') conn.endheaders() response = conn.getresponse() data = response.read() print "Status %s Reason \"%s\"" % (response.status, response.reason) print "Data \"%s\"" % data conn.close() #--------------------------------------------------------------------- conn = httplib.HTTPConnection("xxx.xxx.com.au") conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=Default&username=MTS.XXX&userpassword=xxx") conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') conn.putheader('Connection', 'Keep-Alive') conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') conn.putheader('Host', 'xxx.xxx.com.au') conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') conn.putheader('Accept-Language', 'en') conn.putheader('Accept-Charset', 'iso-8859-1,*,utf-8') conn.endheaders() response = conn.getresponse() data = response.read() print "Status %s Reason \"%s\"" % (response.status, response.reason) print "Data \"%s\"" % data conn.close() #--------------------------------------------------------------------- conn = httplib.HTTPConnection("xxx.xxx.com.au") conn.putrequest("GET", "/servlets/glog.webserver.servlet.umt.Login?redir=/servlets/glog.webserver.util.FrameGC3Servlet&namespace=Default&username=MTS.XXX&userpassword=xxx") conn.putheader('Referer', 'http://xxx.xxx.com.au/toll/authentication/Login.jsp') conn.putheader('Connection', 'Keep-Alive') conn.putheader('User-Agent', 'Mozilla/4.05 [fr] (X11; I; SunOS 5.7 sun4m)') conn.putheader('Host', 'xxx.xxx.com.au') conn.putheader('Accept', 'image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*') conn.putheader('Accept-Language', 'en') conn.putheader('Accept-Charset', 'iso-8859-1,*,utf-8') conn.endheaders() response = conn.getresponse() data = response.read() conn.close() print "Status %s Reason \"%s\"" % (response.status, response.reason) print "Data \"%s\"" % data #--------------------------------------------------------------------- # HTTPD Status # # 200 - OK # 302 - Moved temporarily (a redirect) # 404 - Server failure (page not found) # #---------------------------------------------------------------------