웹세션 유지한채로 통신하기
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()
'Python' 카테고리의 다른 글
펌웨어 전체 파일에서 하드코딩된 스트링 찾을때.. (0) | 2016.10.09 |
---|---|
dbus tree (0) | 2016.04.27 |
python iterator 관련itertools 패키지 및 메소드 정리 (0) | 2014.06.01 |
python string 관련 메소드 정리 (0) | 2014.06.01 |
[ Python 2.7 ] 키보드 마우스 후킹 ( Key Mouse Event hooking ) (0) | 2014.05.24 |