- 1 Introduction
- 2. Build a local http server
- 2.1.Python installation and setup
- 2.2.Python server setup and testing
- 3. Installation and registration of cpolar
- 3.1 Cpolar cloud settings
- 3.2 Cpolar Local Settings
- 4. Public network access test
- 5 Conclusion
Reprinted from the article of remote intranet penetration: [Python] Quickly and easily build an HTTP server and access “cpolar intranet penetration” from the public network
As a relatively popular programming language, Python has simple syntax and clear statements, and python has good compatibility. It can be easily connected with modules established in other programming languages (such as C/C++), and python is rich in A powerful library that can be easily called after packaging, so it is very popular.
Today we will try to use python to build a simple http server to display the specified directories and files on the local computer.
2. Build a local http server
Generally speaking, Python’s simple http server does not rely on complex server programs such as Apache and IIS, because it comes with a single line of commands to create an http service. But relatively, this simple http service cannot provide complex functions, and can only provide relatively simple directory services. But for those who want to learn and be familiar with python, this is another necessary step.
2.1.Python installation and setup
First, we need to install the python program locally. The Python program can be downloaded from its official website (www.python.org/) corresponding to the operating system version. The author uses the Windows operating system, so choose the Windows version to download.
After the Python download is complete, click the installer.exe directly to install it. At the same time, it should be noted that during the installation process, it is necessary to check the
Add python.exe to PATH option.
After completing the installation of the python program, we can start to build the python http server
2.2.Python server setup and testing
Since python has a built-in simple http service package, for python, you only need to enter a line of commands to open the http service easily. Of course, to run a web page, the web page needs to have display content. Therefore, we can first create a folder for storing web page files. For example, the author created a new “test” folder under the E drive of the local computer
Then, run the
command prompt interface of the local computer as an administrator, and enter the command to transfer to the hard disk where the file is stored
Go to the folder you want to share
Then enter the command
start http service
- If the Python version is 2.x, enter the command
python -m SimpleHTTPServer 8081
- If the Python version is 3.x, enter the command
python -m http.server 8001
Among them, 8081 is the output port of the server to be built, as long as you choose an unoccupied port. If a firewall prompt message appears, just select
After the command line is entered, python gives feedback
Serving HTTP on 0.0.0.0 port 8081 ..., which means that our python http service has been successfully opened under the local port 8081.
Then we enter
localhost:8081 in the address bar of the browser on the local computer to open the files in the folder to be shared.
Being able to see these contents means that the http service of python on the local computer has been enabled, and the files in this folder can already be checked. Similarly, if we put webpage files in this folder, they can also be displayed as webpages.
At this time, for devices under the same LAN, just enter the ip address of the local computer + port number (the specific format is 192.168.XXX.XXX:port number) in the browser, and the python web page can be displayed.
However, web pages that cannot be accessed on the public Internet always feel lack of soul, so we can use cpolar intranet penetration to create an intranet penetration data tunnel, so that we can access python under public Internet conditions.
3.cpolar installation and registration
Similarly, we can find the software corresponding to the operating system version on the official website of cpolar (https://www.cpolar.com/). The author also chooses the Windows version here.
After the Cpolar software is downloaded, decompress the compressed package and double-click the
.msi file to install it automatically. We only need to click
Next all the way.
Since cpolar will create an independent data tunnel for each user, supplemented by user passwords and token codes to ensure data security, we need to register users before using cpolar. The registration process is also very simple, just click
User Registration in the upper right corner of the cpolar homepage, fill in the necessary information on the registration page, and the registration will be completed.
3.1 Cpolar cloud settings
After completing the installation and registration of cpolar, we can start to use cpolar to create an intranet penetration data tunnel to connect the python web page of the local computer with the public Internet. It should be noted that the data tunnel of the free version of cpolar is reset every 24 hours. The author does not want to reset the data tunnel settings every day, so I upgraded cpolar to the VIP version in order to obtain a long-term stable intranet penetration data tunnel.
To generate a long-term and stable intranet penetration data tunnel, we must first visit the cpolar official website and log in, and on the left side of the “Dashboard” page, find and click the
Reserved button to enter the “Reserved” “page.
On the “Reservation” page, we can see that cpolar provides data tunnel reservation items for various protocols. The python server uses the http protocol, so we find the
reserve second-level subdomain name field. Of course, if you have already purchased your own domain name from a domain name provider, you can also select the “Reserve Custom Domain Name” column.
In the “reserved second-level subdomain name” field, we need to set the information of the second-level subdomain name we intend to reserve, and the information set will also become the tunnel entrance for us to access the local python server on the public Internet (the address of the public Internet part). The specific information that needs to be set is:
Region: the region where the server is located, just select the nearest one
Second-level domain namewill eventually appear in the generated public Internet address as one of the identifiers of the network address
descriptioncan be regarded as the description of this data tunnel, which can be distinguished from other tunnels
After entering these settings, you can click the
Reserve button on the right to preserve this data tunnel. If we don’t want the entrance of this tunnel anymore, we can also click the “x” on the right to delete the tunnel easily
3.2 Cpolar local settings
After completing the cpolar cloud setting, we go back to the local computer, open and log in the cpolar client (you can enter localhost:9200 in the browser to access directly, or click the shortcut of the cpolar client in the start menu).
Create Tunnel button on the left side of the main interface of the client to enter the local tunnel creation page (if you want to create a temporary data tunnel whose address is reset every 24 hours, you can Set it here directly, no need to set a blank data tunnel on the official website of cpolar).
On this page, several information settings also need to be made, including:
Tunnel name– can be seen as cpolar local tunnel information comment, as long as it is convenient for us to distinguish;
protocol–tomcat outputs web pages, so choose http protocol;
Local address–The local address is the output port number of the local website. We set 8081 as the output port before, so fill in 8081 here;
Domain name type–In this example, we have reserved the data tunnel of the second-level subdomain name in the cpolar cloud, so check the “Second-level subdomain name” (if the reservation is Custom domain name, then check the custom domain name), and fill in the reserved second-level subdomain name in the “Sub Domain” column on the next line, here we fill in “pythonweb” (if you are only creating a temporary data tunnel, directly check “Random domain name”, the network address is generated by the cpolar client);
Region– the same as the cpolar cloud setting, we fill in the nearest location according to the actual location;
After completing these settings, you can click the
Create button at the bottom of the page to connect the local python server web page with the second-level subdomain reserved in the cpolar cloud to generate a complete intranet penetration data tunnel.
After the tunnel is created, cpolar will automatically jump to the
Tunnel List page, where you can see the status of the data tunnel (whether it is unblocked), or control Opening, closing or deleting of tunnels. If you need to change the information of the tunnel, you can also use the “Edit” button here
4. Public network access test
After the data tunnel is established, we can click
Status on the left side of the cpolar client–
Online Tunnel List. Find a public internet address where you can access your local python server page.
Just enter this address into the browser address, and you can easily access the python server page on the local computer.
So far, we have successfully used python to build a simple server page, and created a data tunnel for it through cpolar that can penetrate the intranet barrier, and publish this python page to the public Internet. In fact, as long as we know the output port number of the webpage (or software), we can use cpolar to penetrate the intranet, allowing us to access the local webpage (or software) on the public Internet.