如何雙擊連上校園網NCUWLAN?---bat+Python3給出了可行性答案

由於經常有小夥伴連不上南昌大學的校園網(主要是很多人打不開登錄界面),這裏就給出一個方案,只要我們雙擊鼠標就可連接和註銷。(本方案一共有2個.py文件和2個.bat文件,需要懂一點編程,感興趣就可以往下看)

雖然校園網比較慢,可以作爲它也有神奇的地方,比如可以輕鬆越過某些牆...


login.py

#   coding=utf-8
'''
Author:Zlonqi
Date:2018-5-8
E-mail:[email protected]
PE:win8.1,Python3.6
Describe: Connect to NCUWLAN
'''


import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
import urllib.error
import requests
from requests.exceptions import RequestException
import subprocess
import time


login_url = "http://222.204.3.221:803/srun_portal_pc.php" # 登錄post的URL
info_url = "http://222.204.3.221:802/srun_portal_pc_succeed.php"  # 獲取用戶信息URL


class NCU_WLAN():


    def login(self): 
        data = urllib.parse.urlencode({
            "action": "login",
            "username": '8001715135',
            "password": "{B}MTc0NDMy",
            "ac_id": '1',
            "save_me": '1',
            "ajax": '1'
        }).encode('utf-8')
        try:
            post = urllib.request.urlopen(url=login_url, data=data)
            html = urllib.request.urlopen(url=info_url).read()
            soup = BeautifulSoup(html, "lxml")
            print(soup.find("title").get_text())
            for tr in soup.findAll("tr", {'height': '30'}):
                td = tr.findAll("td")
                print(td[0].get_text() + "\t" + td[1].get_text())
        except urllib.error.HTTPError as e:
            print(e.reason)
        except urllib.error.URLError as e:
            print(e.reason)


    def isconnection(self):
        try:
            q = requests.get("http://www.baidu.com")
            soup=BeautifulSoup(q.content.decode('utf-8'),"lxml")
            title=soup.find("title")
            if title:
                return True
            else:
                return False
        except RequestException as e:
            print(e)
            return False


    def main(self):
        #subprocess.Popen("netsh interface set interface wlan disabled", shell=True)
        while True:
            if not self.isconnection():
                self.login()
                time.sleep(1)
            else:
                print('已連接')
                break


if __name__ == '__main__':
    ncu = NCU_WLAN()
    ncu.main()

下面用chrome或firefox打開登錄頁面,打不開的在地址欄輸入http://222.204.3.221:801/srun_portal_pc.php?ac_id=1&url=

然後填寫自己的學號和密碼,

fn+f12打開下面截圖的右邊視圖,選擇Network模式,

點擊登錄

點擊登錄後會出現一個報文

點擊該報文後打開了它的內容:最右邊部分

找到劃紅線的部分就是加密後的密碼(登錄校園網時密碼時經過加密的,但我發現學校其它的平臺登錄時的信息都是明文傳輸的)

將紅線處的密碼填到上面login.py的對應處,同時將學號也改過來,保存

logout.py也只要將學號和密碼改成你們自己的就行

logout.py

#   coding=utf-8
'''
Author:Zlonqi
Date:2018-5-8
E-mail:[email protected]
斷開校園網
'''
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
import urllib.error

logout_url = "http://222.204.3.221:802/srun_portal_pc_succeed.php"  # 登出post的URL
info_url = "http://222.204.3.221:802/srun_portal_pc_succeed.php"  # 獲取用戶信息URL

class NCU_WLAN():

    def logout(self):
        try:
            html = urllib.request.urlopen(url=info_url).read()
            soup = BeautifulSoup(html, "lxml")
            D=dict()
            for ms in soup.findAll("input",{'type':'hidden'}):
                D[ms['name']]=ms['value']
            data=urllib.parse.urlencode(D).encode('utf-8')
            post = urllib.request.Request(url=logout_url, method='POST',data=data)
            urllib.request.urlopen(post)
        except urllib.error.HTTPError as e:
            print(e.reason)
        except urllib.error.URLError as e:
            print(e.reason)

if __name__ == '__main__':
    ncu = NCU_WLAN()
    ncu.logout()

在login.bat中調用login.py

::::::::::::::::::::::::::::::::::::::::::::
:: Elevate.cmd - Version 4
:: Automatically check & get admin rights
::::::::::::::::::::::::::::::::::::::::::::
 @echo off
 CLS
 ECHO.
 ECHO =============================
 ECHO Running Admin shell
 ECHO =============================

:init
 setlocal DisableDelayedExpansion
 set cmdInvoke=1
 set winSysFolder=System32
 set "batchPath=%~0"
 for %%k in (%0) do set batchName=%%~nk
 set "vbsGetPrivileges=%temp%\OEgetPriv_%batchName%.vbs"
 setlocal EnableDelayedExpansion

:checkPrivileges
  NET FILE 1>NUL 2>NUL
  if '%errorlevel%' == '0' ( goto gotPrivileges ) else ( goto getPrivileges )

:getPrivileges
  if '%1'=='ELEV' (echo ELEV & shift /1 & goto gotPrivileges)
  ECHO.
  ECHO **************************************
  ECHO Invoking UAC for Privilege Escalation
  ECHO **************************************

  ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
  ECHO args = "ELEV " >> "%vbsGetPrivileges%"
  ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
  ECHO args = args ^& strArg ^& " "  >> "%vbsGetPrivileges%"
  ECHO Next >> "%vbsGetPrivileges%"

  if '%cmdInvoke%'=='1' goto InvokeCmd 

  ECHO UAC.ShellExecute "!batchPath!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
  goto ExecElevation

:InvokeCmd
  ECHO args = "/c """ + "!batchPath!" + """ " + args >> "%vbsGetPrivileges%"
  ECHO UAC.ShellExecute "%SystemRoot%\%winSysFolder%\cmd.exe", args, "", "runas", 1 >> "%vbsGetPrivileges%"

:ExecElevation
 "%SystemRoot%\%winSysFolder%\WScript.exe" "%vbsGetPrivileges%" %*
 exit /B

:gotPrivileges
 setlocal & cd /d %~dp0
 if '%1'=='ELEV' (del "%vbsGetPrivileges%" 1>nul 2>nul  &  shift /1)

 ::::::::::::::::::::::::::::
 ::START
 ::::::::::::::::::::::::::::
 @echo
echo WScript.sleep 100 > sleep.vbs #設置延遲文件
netsh interface set interface WLAN disabled#關閉無線網卡
Wscript sleep.vbs#等待0.1秒
netsh interface set interface WLAN enabled#啓動無線網卡
Wscript sleep.vbs
netsh WLAN connect NCUWLAN#連接校園網
Wscript sleep.vbs
python "G:\PYworkbench\py\craw spider\NCUWLan\login\login.py"#調用login.py登錄認證,注意自己的文件路徑,和我的不同!
pause

logout.bat

@echo 
python "G:\PYworkbench\py\craw spider\NCUWLan\logout\logout.py"

Demon:


經多次實測,都有效,如雙擊登錄:

註銷一樣的,雙擊logout.bat就行

最後,感興趣的同學可以自己去看下js對密碼的加密方式,這樣可以將加密方式寫入登錄腳本,直接輸學號就行,不必通過瀏覽器抓包來找到加密結果,我就不在這囉嗦了。

有什麼問題可以email我(代碼中有我的郵箱)





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章