Use command lines to automate configurations of broadband Routers

Source: Internet
Author: User

Nowadays, many companies and enterprises are connected to their own networks. Especially for small enterprises with small size and few employees, it is unnecessary to apply for high-capacity fiber-optic bandwidth, therefore, using ADSL has become the choice of many leaders. The entire company only needs to buy a Broadband Router and then complete the company's network requirements through simple configuration.
However, because the hardware inside the Broadband Router is very simple and its functions are not developed, it is difficult to compare with enterprise-level routers or layer-3 switches. Therefore, there is a lack of functions in managing and restricting Internet access for employees, especially in time-based management. For example, the company requires that some employees be prohibited from accessing the Internet at work, but there is no restriction on the rest time. Because most broadband routers do not have time-based settings, so the only feasible thing is that the company's network administrator manually configures a Broadband Router to restrict employees before going to work, and then sets another option to cancel the restriction during the break.

Every day, you have to log on to and configure a Broadband Router repeatedly. Each configuration requires you to access the management interface of the Broadband Router through a browser, which is inconvenient to operate, it also increases the work of network administrators to a certain extent. Is there any way to enable the computer to automatically connect to the Broadband Router and add restrictions before going to work?

The key to solving the above automation problem is to set the Broadband Router under the command line. If you can modify the parameters of the Broadband Router through a single command, then, we can use the batch processing file + scheduled task method to automate the modification settings.

Before explaining how to control a Broadband Router under the command line, we need to understand the CURL tool. In "using command line to play with a Broadband Router (on)", we mainly introduce the CURL usage and commands, only when you are familiar with CURL can you automate the modification of the internal parameters of a Broadband Router in "using command line to play with a Broadband Router (medium, bottom.

1. What is CURL:

Like HTML, Curl is a text markup language. It is both a text and an object-oriented programming language that supports multiple inheritance. The disadvantage of Curl is that a single form breaks the separation of content information, forms, and behavior brought by HTML, CSS, and Javascript. The above is a professional explanation of CURL. Although CURL is widely used in LINUX and other operating systems, its application in the windows operating system has gradually become a concern.

In a simple sense, curl is a tool that uses URL syntax to transmit files, supports HTTP, HTTPS, FTP, FTPS, DICT, TELNET, LDAP, FILE, GOPHER, and other protocols, and provides high security. That is to say, we can use the curl command to interact with HTTP-based pages.

The CURL command has become one of the built-in command line tools on apple, so its importance is obvious.

Ii. simple use of CURL:

First, download the CURL, decompress it to any directory, and enter the command line mode through "start-> Run-> Enter CMD" on the desktop, change the current directory to the decompressed directory of CURL. (1)

Figure 1: select the extract directory

TIPS:

We can use CD \ to return to the disk root directory and use cd curl to enter the CURL directory.

CURL supports many parameters, which can be obtained through curl-help. Enter CURL-help in the curl directory and press Enter. (2)

Figure 2: Enter the CURL directory

Ii. simple use of CURL:

First, download the CURL, decompress it to any directory, and enter the command line mode through "start-> Run-> Enter CMD" on the desktop, change the current directory to the decompressed directory of CURL. (1)

Figure 1: select the extract directory

TIPS:

We can use CD \ to return to the disk root directory and use cd curl to enter the CURL directory.

CURL supports many parameters, which can be obtained through curl-help. Enter CURL-help in the curl directory and press Enter. (2)

Figure 2: Enter the CURL directory

Here we will only introduce some useful information for you. After understanding these parameters, you can go to "use command lines to play with a Broadband Router (below).

(1) Output page information parameters:

After CURL, we can directly follow the page address to display the source code of the corresponding page in command line mode.

Curl www.sohu.com

// Display all the code content on the www.sohu.com page in command line mode (3)

Figure 3: Output page information parameters and click to view the large image)

(2) Save the corresponding page:

If you want to directly use the CURL command to save all the content of a page, the command is as follows:

Curl www.sohu.com> softer.htm

// Enter the corresponding information on the www.sohu.com page. It takes a certain amount of time to save the data. If the % column shows 100, all the data is complete. (4)

Figure 4: Save the corresponding page and click to view the big picture)

TIPS:

In fact, do not use> and directly use the CURL-o parameters can also achieve the above function, there is a built-in option parameter in CURL, with curl-o softer.htm http://www.sohu.com can also save www.sohu.compage softer.htm file.

(3) Access the user name and password-based authentication page:

If you need to enter the user name and password to verify the access to the page, you can also use the-u parameter of the CURL command. For example, if you want to access the http: // 192.168.1.1 address, the actual content of this address can be viewed only after you enter the correct user name and password. (5)

Figure 5: Access http: // 192.168.1.1

If you do not enter the user name and password or enter an incorrect password, the page displays an error message. (6)

Figure 6: error message

Assume that our user name is admin, the password is 198029, and the address of the page to be accessed is http: // 192.168.1.1. Therefore, you can use CURL to output and save the real page.

Curl-u admin: 198029 http: // 192.168.1.1

// Access the 192.168.1.1 page. Enter the username admin and password 198029 when you need password verification. The page information after verification is displayed in command line mode. (7)

Figure 7: Click to view the big picture through verification information)

(4) proxy-based access:

Sometimes we may need to use the proxy server to access a page. If the proxy server is not set to directly use curl-o to save the page, the-x parameter can be used.

It is assumed that the IP address 192.168.1.1 is still accessed, but the proxy server 10.91.30.1: 8080 must be used. The CURL command is as follows --

Curl-x 10.91.30.1: 8080-o softer.html http: // 192.168.1.1

// Access the http: // 192.168.1.1page through the proxy server 10.91.30.1: 8080, and save the page information to the softer.html file.

(5) Modify useragent:

Many times, when we access a website, there will be an error message. One of these error messages is caused by inconsistent browser types. That is to say, the page will read the useragent information of the visitor's browser. If this information is not within the authorized browser scope of the page, it cannot be accessed. This is the most common case when accessing wireless networks through mobile phones and laptops. We cannot use tools such as Internet Explorer and MAXTHON to browse. We can only use the registry to modify useragent to confuse the other party and achieve access. Of course, you can also use the-A parameter in the command line curl.

You can use the-A parameter to specify the type and version of your browser. For example, curl-A "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)"-x http://www.sohu.com.

In this way, when the server receives the access request, it will think that you are an IE6.0 running on Windows 2000. In fact, you may use an apple. -A followed by "Mozilla/4.73 [en] (X11; U; Linux 2.2; 15 i686" can tell the other party that you are a pc and the operating system is Linux, the Netscape 4.73 browser is used.

(6) Anti-leech protection for CURL:

The common restriction method on the server side is to check the referer for http access. For example, if you first access the homepage and then access the specified download page, the referer address for the second visit is the address of the page after the first successful access. In this way, as long as the server finds that the referer address accessed for a download page is not the address of the home page, it can be determined that it is a leeching. When we find that the link is leeching, our access will fail.

In fact, we can solve this problem by setting the referer parameter-e provided by curl.

Curl-e "mail.sohu.com"-o softer.html http://www.sohu.com

// It indicates that we access www.sohu.com by clicking the link on the mail.sohu.com page. After bypassing the server-side anti-leech restriction, save the page to the softer.html file.

(7) page interaction parameters:

Many times, server pages are built based on dynamic languages such as CGI, PHP, and ASP. This increases the interaction between visitors and page information, that is, different user names and passwords correspond to different content. How can we achieve this interaction through curl?

TIPS:

To put it bluntly, accessing the management interface of the Broadband Router and changing various parameters is also an interactive behavior. As long as we find the modified parameters and interaction behavior, we can use CURL to simulate these operations, you can achieve the purpose of managing a Broadband Router in the command line. Of course, the specific operations will be described in "using the command line to play with a Broadband Router (below.

There are two main ways to interact with HTTP pages and submit forms: GET and POST.

If you use the GET operation, you don't need to add any parameters. Simply write the variables in the URL address that follows. For example, curl http: // 192.168.1.1/login. cgi? User = softer & password = 198029, then access http: // 192.168.1.1/login. on the cgi page, the user and password parameters corresponding to the page are set to softer and 198029 in sequence to implement the login function.

The post mode parameter is-d. After the post mode is used, the above GET Operation Command is evolved into curl-d "user = softer & password = 198029" http: // 192.168.1.1/login. cgi, which is equivalent to sending a login request to the site. Whether to use the GET mode or POST mode depends on the settings of the server program. In general, either of the two modes can work.

Summary:

There are many other CURL parameters and their functions are powerful. Of course, the parameters and commands introduced in this article are just to help us better understand the meaning of the CURL command line in the article "using command line to play with a Broadband Router (medium, bottom, only by having mastered the basic theories and preparation knowledge introduced in this article can we be more comfortable playing with broadband routers under the command line.(

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.