校園網自動登入程式

來源:互聯網
上載者:User

標籤:

最近趁校園網免費在抓論文,然而臉黑,老被校園網踢,愛過。

於是寫了一個保駕護航的自動登入~

 

Step1:分析包

之前我天真的以為裡面只要寫了使用者名稱和密碼就行= = 啊我要找時間補電腦網路。。

在瀏覽器裝了FireBug外掛程式,手動登入了一下抓下了包。

分析一下:

1.在網路選項下,看到發送的地址是,滑鼠移上去可以看到具體地址,不好就不截了。

2.展開它,在要求標頭資訊裡可以看到一堆東西,這裡只需要Host 和Referer就差不多了

3.在Post欄,看到具體發送的參數

 

然後基本資料就準備好了。

 

Step2:檢測是否有網路連接

開啟一個網頁看能否開啟,由於在未登入狀態開啟網頁會被定向到登入的頁面(也可能直接打不開),所以先檢測是否能開啟,如果是的話,分析頁面元素檢測Title是否一致。

在這裡微軟大法好用了Bing當作測試頁面=w=

 

Step3:構建自己的資料包並發送

這裡用Python大法好。

 

具體看代碼

 

 1 import os 2 from bs4 import  BeautifulSoup 3 from urllib.parse import urlencode 4 from urllib.request import urlopen 5 from urllib.request import build_opener 6 from urllib.request import HTTPCookieProcessor 7 from urllib.request import Request 8 import http.cookiejar 9 import time10 def CheckLink():11     url = ‘http://cn.bing.com‘12 13     try:14         html = urlopen(url).read().decode("utf-8")15     except:16         return False17 18     bsObj = BeautifulSoup(html)19     print (bsObj.title)20     if(bsObj.title == None or bsObj.title.get_text() == ‘登入‘):21         return False22     return True23 24 25 def MakeLink():26 27     url = ‘http://10.0.0.55:801/include/auth_action.php‘28     #set Post paras29     userData = {30         "action":"login",31         "username":"",32         "password":"",33         "ac_id" : "1",34         "user_ip":"",35         "nas_ip":"",36         "user_mac":"",37         "save_me":"1",38         "ajax":"1"39     }40     postData = urlencode(userData).encode(encoding=‘utf-8‘)41     headers = {42         "host":‘10.0.0.55:804‘,43         "Referer":‘http://10.0.0.55:801/srun_portal_pc.php‘44     }45     cookiejar = http.cookiejar.CookieJar()46 47     #open in glabal48     opener = build_opener(HTTPCookieProcessor(cookiejar))49 50     #get cookiejar51     req = Request(url, postData, headers)52     result = opener.open(req)53     print (result.read())54 55     return56 57 def main():58     while(True):59         if(CheckLink() == False):60             print (‘outline‘)61             MakeLink()62         else: print(‘inline‘)63         time.sleep(60)64 65 if __name__ == ‘__main__‘:66     main()
View Code

 

校園網自動登入程式

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.