• Program
  • Server
  • Development Tool
  • Blockchain
  • Database
  • Artificial Intelligence
  • Blogs
Position: Home > Server > Content

Server enables elegant Internet access

Time:2022-6-18

Internet access in schools requires identity authentication. This identity authentication mechanism is troublesome for people who often use the Internet. In order to solve this problem, several feasible methods without manual authentication are proposed here to solve the pain point of identity authentication.

  • Personal use host

For personal computers, the simplest is to use Google browser and other browsers that have the ability to remember the account and password. Of course, you can’t avoid manual clicking. For personal notebooks, I suggest that you can buy a newwifi router to manually brush the old hairy padavan firmware, or go to the salted fish to buy the brushed old hairy router. The price is about forty or fifty yuan, which is easy, affordable and easy. The network authentication can be automatically performed through the old maozi router, and the computers connected to the WiFi do not need to be authenticated.

  • Server Internet access

Personal computers can access the internet no matter what, just because it is easy or not. This article focuses on the Internet access of servers in the computer room. When we connect the servers in the LAN through SSH, we will encounter the situation that the servers cannot be connected to the network (note that the SSH connection host is in the same LAN, and the server cannot be connected to the network means that it cannot communicate with the external network, such as Baidu, Google and other websites). Although the network cable is plugged in, the annoying authentication mechanism makes us need to authenticate. We can’t authenticate only through the command line. Unless we use special means to call the visual browser interface, we can only go to the computer room for manual authentication, and then go back to the laboratory to use the server.

  • Writing scripts to access the Internet

For each authentication, access the 192.168.6.1 interface through the browser, fill in the online account password, and click the submit button to access the Internet. So the main idea is to use code to implement this process, eliminating all manual operations. The environment of this article is to write Python code under the Ubuntu system. The browser is Firefox. In fact, there are only some differences in details between windows and Ubuntu systems.

There are two ways to simulate the submission process. The first one is to grab the data packets, analyze the data packets, and then simulate the request to implement the process. However, there are many parameters in the process, so it takes a little effort to guess the meaning of a large number of submitted parameters.

The second is to use the selenium module of Python. We use this module to control the behavior of the browser. After filling in the form, click the submit button to simulate the whole process.

  • Scripting environment

Python parser requires that after version 3.0, thepip install selenium==4.0.0Installing modules

Then you only need the Firefox browser and the webdriver driver corresponding to the browser version. The code here uses the Firefox browser. Similarly, Google browser can be used, but the code needs to be modified. The driver needs to correspond to the browser version, otherwise there may be various errors.

Webdriver download address of chrome

Webdriver download address of Firefox

Move the downloaded file to /user/bin under Linux and grant execution permission

mv chromedriver /usr/bin/
chmod +x /usr/bin/chromedriver
  • Code writing

We separate the account password from the code and create a user Txt file, which stores your account and password,separate.

admin,password

The account and password can be easily modified by putting them in a separate file, and then use Python code to read the account and password

with open('./user.txt') as f:
    line = f.readline()
    if line:
        mess = re.split(',|,', line)
        account, password = mess[0], mess[1]

After reading the account and password, we need to use selenium to drive our browser to open 192.168.6.1. Here are a bunch of basic settings. One thing to note is that when setting the log path, different versions of selenium will have different writing methods, and it is recommended to write each path as an absolute path.

options = webdriver.FirefoxOptions()
options.add_argument("--no-sandbox")
options. add_ Argument ("--headless") \
options.add_argument("--disable-gpu")
tmp_service = Service(log_path="/home/geckodriver.log", executable_path='geckodriver')
driver = webdriver.Firefox(options=options, service=tmp_service)
driver.get('http://192.168.6.1')

After opening the interface, we use XPath to locate the element, find the user name and password element, fill in the account password, and then locate the submit button to simulate clicking. Throw an exception to an exception using try

try:
    driver.find_element(By.XPATH, '//form[@name="f1"]/input[@name="DDDDD"]').send_keys(mess[0])
    driver.find_element(By.XPATH, '//form[@name="f1"]/input[@name="upass"]').send_keys(mess[1])
    driver.find_element(By.XPATH, '//form[@name="f1"]/input[@type="submit"]').click()
    time.sleep(0.2)
    Print ('you have successfully logged in!!! -- East Lake White Goose ')
except Exception as e:
    print(e)
    Print ('the device is online!!! -- East Lake White Goose ')
    driver.quit()

Here is the complete code:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.common.action_chains import ActionChains
import re
from selenium.webdriver.firefox.service import Service

With open ('./user.txt') as f: \
    line = f.readline()
    if line:
        mess = re.split(',|,', line)

        options = webdriver.FirefoxOptions()
        options.add_argument("--no-sandbox")
        options.add_argument("--headless")
        options.add_argument("--disable-gpu")
        tmp_ Service = Service (log\u path= "/home/geckodriver.log", executable\u path='geckodriver') \
        driver = webdriver.Firefox(options=options, service=tmp_service)
        driver.get('http://192.168.6.1')
        try:
            driver.find_element(By.XPATH, '//form[@name="f1"]/input[@name="DDDDD"]').send_keys(mess[0])
            driver.find_element(By.XPATH, '//form[@name="f1"]/input[@name="upass"]').send_keys(mess[1])
            driver.find_element(By.XPATH, '//form[@name="f1"]/input[@type="submit"]').click()
            time.sleep(0.2)
            Print ('you have successfully logged in!!! -- East Lake White Goose ')
        except Exception as e:
            print(e)
            Print ('the device is online!!! -- East Lake White Goose ')
        driver.quit()
    else:
        Print ('Please enter the account and password in user.txt ')
  • Set execution command

At this point, use the commandpython login.pyIf you don’t report an error, you’ll be more than half successful

However, there are usually many Python parsers, and this command can only be used in login Py directory, so we need to get the absolute path of the python parser and login The absolute path of. Py, which is used to execute commands.

When the command can be executed successfully, we will write the command using the absolute path to Zshrc or In the bashrc file, it depends on which shell you use and which shell you use to write commands to the corresponding file

Alias'zjut'= 'your command'

Then usesource ~/.zshrcUpdate your command and try the effect at last.

Here, you need to have absolute paths in your code and set the log path. In this way, you can access the Internet gracefully. Interested students can write an exit and login script, so that they can easily log in or log out through the command line.

  • Automatic execution

Maybe the command line is still very troublesome for many students. Here is the idea of executing scripts regularly every day to achieve a permanent online effect. Here, we need to use the Linux cron to implement it. The cron can set scheduled tasks, which is provided by Ubuntu.

Using commandscrontab -eEdit automatically executed commands and the time of each automatic execution

30 8 * * * /you_path/python /you_path/login.py

The syntax here means to automatically execute the following commands at 8:30 every day. Required after modificationservice cron restartRestart the service to take effect.

  • summary

The whole article is mainly aimed at the solution to the Internet access of Linux servers that need campus network authentication. It can be set as a short command line or an automatically executed task. The code idea uses the selenium module of Python to simulate the user’s operation behavior on the browser to achieve the goal. This method is much simpler than the construction request.

The article is for study.

——East Lake white goose

Tags: Account and password, Browser, code, command, The server

Recommended Today

Long-form diagram of java reflection mechanism and its application scenarios

1. What is java reflection? In the object-oriented programming process of java, we usually need to know a Class class first, and thennew classname()way to get an object of this class. That is to say, we need to know which class we want to instantiate and which method to run when we write the code […]

  • Uncover the secret behind sealer to achieve one-click delivery of the entire cluster | Dragon Lizard Technology
  • Nginx tuning: gzip related settings
  • Leaping evolution from concept to practice! How does the cloud's native "immune system" fight organically?
  • In the era of Hadoop 3.0, how can you not understand EC erasure coding technology? | Personal push technology practice
  • Difference between Origin and Referer in HTTP?
  • Little raccoon cms—collecting comics with a train collector
  • Which is the best free software for drawing flowcharts
  • FreeBSD – Analysis of basic data structure of ext2 file system
  • Apache POI reads Microsoft Office Excel documents
  • Detailed explanation of the method of using zabbix to monitor oracle database
Pre: Create a pure springboot project
Next: Google plugin (set page background)

    Tags

    address algorithm array assembly attribute Browser c Character string Client code command configuration file container data Database Definition Edition element Example file function java javascript Journal link linux Memory method Model Modular mysql node object page parameter php Plug-in unit project python Route source code The server Thread time user

    Recent Posts

    • Long-form diagram of java reflection mechanism and its application scenarios
    • Records about the common problems of Microsoft office 2021 home and student versions _ the shadow of excel in the cell selection is stuck and delayed during the process of pulling down the data area and is out of sync with the mouse pointer!
    • [NOIP2001 Popularization Group] Seek Ranking
    • Introduction to js decorator (introduction to ts decorator)
    • Jiang Hongxiang: Construction of NetEase Data Infrastructure Platform

    Recent Comments

    • Humphry on Answer for Algorithm for the coin removal problem
    • Humphry on Answer for Algorithm for the coin removal problem
    • chiyahoho on Answer for Algorithm for the coin removal problem
    • n͛i͛g͛h͛t͛i͛r͛e͛ on Answer for Algorithm for the coin removal problem
    • Evian on Answer for Algorithm for the coin removal problem

    Categories

    • .NET Core
    • Agile Development
    • Algorithm And Data Structure
    • Android
    • Apple MAC
    • Architecture Design
    • Artificial Intelligence
    • ASP.NET
    • Backend
    • Blockchain
    • C
    • C#
    • C++
    • Cloud
    • Database
    • Design Pattern
    • Development Tool
    • Embedded
    • Erlang
    • Freshman
    • Game
    • Golang
    • HTML/CSS
    • HTML5
    • Informal Essay
    • Information Security
    • IOS
    • Java
    • JavaScript
    • JSP
    • Linux
    • Lua
    • MongoDB
    • MsSql
    • MySql
    • Network Security
    • OOP
    • oracle
    • Other DB
    • Other Technologies
    • Other Technology
    • Perl
    • PHP
    • Program
    • Python
    • Redis
    • Regular Expression
    • Ruby
    • Rust
    • SAP
    • Server
    • Software Testing
    • Team Management
    • VBS
    • VUE
    • WEB Front End
    • Windows
    • XML/XSLT
  • java
  • php
  • python
  • linux
  • windows
  • android
  • ios
  • mysql
  • html
  • .net
  • github
  • node.js

Copyright © 2022 Develop Paper All Rights Reserved      Sitemap    About DevelopPaper    Privacy Policy    Contact Us