2015. 7. 12. 13:33

웹세션 유지한채로 통신하기



import httplib

import urllib

import urllib2

import os 

import time

import getpass

import sys

import telnetlib


RouterIP = "192.168.123.1"



def HttpAdminLogin():

#print ":::     CONNECT ADMIN SESSION     "

loginURL2 = "http://"+RouterIP+"/ap_login.asp"

params2 = {"page":"ap_login.asp","http_passwd":"YWRtaW4=",'hidden_action':"Login"}

params2 = urllib.urlencode(params2)

try :

conn = urllib2.Request(loginURL2,params2)

conn.add_header("Content-Type","application/x-www-form-urlencoded")

response = urllib2.urlopen(conn)

cookie = response.headers.get('Set-Cookie')  ## 여기서 쿠키값을 가져옴

except :

print "CONNECTION ERROR "

return


time.sleep(1)

## iptables OPEN

print ":::     IPTABLES FIREWALL IS OPENED      "

loginURL = "http://"+RouterIP+"/test.asp"

params ={"page":"ap_login.asp","http_passwd":"YWRtaW4=",'hidden_action':"Login"}

params = urllib.urlencode(params)

try :

conn = urllib2.Request(loginURL,params)

conn.add_header("Content-Type","application/x-www-form-urlencoded")

conn.add_header("cookie",cookie)  ## 여기서 쿠기값을 저장 

response = urllib2.urlopen(conn)

except :

print "IPTABLES FIREWALL OPEN FAIL"

return 


def main():

try :

RouterIP = sys.argv[1]

except :

RouterIP = "192.168.123.1"


print ":::     Home Router IP -> " + str(RouterIP)

HttpAdminLogin()

if __name__ == "__main__":

main()



Posted by k1rha