Campus Network Automatic Login Program

Source: Internet
Author: User
Tags urlencode

Recently took advantage of the campus network for free in the paper, but face black, the old school network kicked, love.

Then wrote a escort of automatic login ~

STEP1: Analysis Package

Before I naively thought that just write the user name and password on the line = Ah I want to find time to repair computer network.

In the browser installed Firebug plug-in, manually login and grabbed the package.

Analysis:

1. Under the network options, see the address is sent, the mouse can see the specific address, the bad is not cut.

2. Expand it, you can see a bunch of things in the request header, it's just about the host and Referer.

3. In the post bar, see the specific sent parameters

Then the basic information is ready.

STEP2: Detecting If there is an Internet connection

Open a Web page to see if it can be opened, because the open Web page is not logged in will be directed to the login page (also may not open), so first detect whether it can be opened, if so, the analysis page element detection title is consistent.

Here Microsoft Dafa works with Bing as a test page =w=

STEP3: Build your own packets and send

It is good to use Python Dafa here.

Specific look at the code

1 ImportOS2  fromBs4ImportBeautifulSoup3  fromUrllib.parseImportUrlEncode4  fromUrllib.requestImportUrlopen5  fromUrllib.requestImportBuild_opener6  fromUrllib.requestImportHttpcookieprocessor7  fromUrllib.requestImportRequest8 ImportHttp.cookiejar9 Import TimeTen defChecklink (): OneURL ='http://cn.bing.com' A  -     Try: -html = urlopen (URL). read (). Decode ("Utf-8") the     except: -         returnFalse -  -Bsobj =BeautifulSoup (HTML) +     Print(Bsobj.title) -     if(Bsobj.title = = NoneorBsObj.title.get_text () = ='Login'): +         returnFalse A     returnTrue at  -  - defMakelink (): -  -URL ='http://10.0.0.55:801/include/auth_action.php' -     #SET Post paras inUserData = { -         "Action":"Login", to         "username":"", +         "Password":"", -         "ac_id":"1", the         "user_ip":"", *         "nas_ip":"", $         "User_mac":"",Panax Notoginseng         "Save_me":"1", -         "Ajax":"1" the     } +PostData = UrlEncode (userData). Encode (encoding='Utf-8') Aheaders = { the         "Host":'10.0.0.55:804', +         "Referer":'http://10.0.0.55:801/srun_portal_pc.php' -     } $Cookiejar =Http.cookiejar.CookieJar () $  -     #Open in Glabal -Opener =Build_opener (Httpcookieprocessor (Cookiejar)) the  -     #Get CookiejarWuyireq =Request (URL, postdata, headers) theresult =Opener.open (req) -     Print(Result.read ()) Wu  -     return About  $ defMain (): -      while(True): -         if(Checklink () = =False): -             Print('Outline') A Makelink () +         Else:Print('inline') theTime.sleep (60) -  $ if __name__=='__main__': theMain ()
View Code

Automatic login program on campus network

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.