VPN sharing method and device, electronic equipment and storage medium
By displaying prompt information when the target device connects to WiFi hotspots and adding client rules, the security problem when the device shares a VPN is solved, and the security and control rights of the target device to access the VPN are achieved.
Patent Information
- Application Number
- CN202310789091.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-29
- Publication Date
- 2024-12-31
AI Technical Summary
The prior art is difficult to effectively solve the problem of how to share a VPN with a device, especially allowing the target device to access the currently connected VPN while ensuring security.
By listening to the target device to display a prompt message when connecting to a WiFi hotspot, users can choose whether to allow it to access the current VPN, and add client rules when allowed to achieve forwarding of data packets to ensure data security.
It realizes that while allowing target devices to access VPN, it improves access security, ensures control over VPN by electronic devices, and prevents unauthorized access.
Smart Images

Figure CN119233366A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of virtual private networks, and in particular to a VPN sharing method, device, electronic device, and storage medium. Background Art
[0002] A Virtual Private Network (VPN) establishes a private network over a public network for encrypted communications. A VPN gateway enables remote access by encrypting data packets and translating their destination addresses. With the advancement of computer technology, VPN applications are becoming increasingly widespread, and how to share VPNs with other devices has become a widespread concern. Summary of the Invention
[0003] To overcome the problems existing in the related art, the present disclosure provides a VPN sharing method, device, electronic device and storage medium.
[0004] According to a first aspect of an embodiment of the present disclosure, a VPN sharing method is provided, the method comprising:
[0005] When monitoring that the target device is connected to a WiFi hotspot, display a prompt message, wherein the prompt message is used to prompt whether to allow the target device to access a target VPN through the electronic device, wherein the target VPN is the VPN currently connected to the electronic device;
[0006] In response to receiving the first feedback information, the target device is allowed to access the target VPN through the electronic device.
[0007] In some embodiments, the prompt information is a prompt window, and the prompt window includes a confirmation control and a denial control. After displaying the prompt information, the method further includes:
[0008] generating the first feedback information in response to a triggering operation on the confirmation control; or
[0009] In response to triggering the denial control, second feedback information is generated, where the second feedback information indicates that the target device is not allowed to access the target VPN through the electronic device.
[0010] In some embodiments, when monitoring that the target device is connected to a WiFi hotspot, displaying a prompt message includes:
[0011] When it is detected that the target device is connected to a WiFi hotspot and the VPN sharing function is enabled on the electronic device, the prompt information is displayed.
[0012] In some embodiments, the method further comprises:
[0013] When the target device is allowed to access the target VPN through the electronic device, client rules are added, and the client rules include at least routing rules. The routing rules are for forwarding data packets to the target VPN through the VPN interface. The data packets are received through the hotspot interface and the source IP address is the first address. The first address is the IP address of the target device.
[0014] In some embodiments, the client rule further includes at least one of the following:
[0015] Obtain the IP address of the hotspot interface;
[0016] Obtain the routing table number corresponding to the VPN interface;
[0017] Obtain the IP address of the target server set by the VPN interface;
[0018] The priority of the routing rule is higher than the priority of the original routing rule, and the original routing rule refers to the routing rule when the target device is connected to the WiFi hotspot and does not access the target VPN;
[0019] The destination IP address of the data packet is modified from the IP address of the hotspot interface to the IP address of the target server.
[0020] In some embodiments, the method further comprises:
[0021] When the VPN function, the WiFi hotspot, and the VPN sharing function are detected to be enabled, an initialization rule is added;
[0022] The initialization rules include at least one of the following:
[0023] Allowing data packets to be forwarded from the hotspot interface to the VPN interface;
[0024] Allowing data packets to be forwarded from the VPN interface to the hotspot interface;
[0025] The source IP address of the data packet sent from the VPN interface is modified to the IP address of the VPN interface.
[0026] In some embodiments, the method further comprises:
[0027] Based on the client rule, receiving a first data packet sent by the target device through the hotspot interface, where the source IP address of the first data packet is the first address and the destination IP address of the first data packet is the IP address of the hotspot interface;
[0028] Forwarding the first data packet from the hotspot interface to the VPN interface;
[0029] Modify the destination IP address of the first data packet from the IP address of the hotspot interface to the IP address of the target server, and modify the source IP address of the first data packet from the first address to the IP address of the VPN interface;
[0030] The modified first data packet is sent to the target VPN.
[0031] In some embodiments, the method further comprises:
[0032] After the VPN sharing function is disabled, the added initialization rules and client rules are deleted.
[0033] In some embodiments, the method further comprises at least one of the following:
[0034] When the WiFi hotspot is turned on, the VPN sharing function is turned on;
[0035] When the WiFi hotspot is turned off, the VPN sharing function is turned off.
[0036] In some embodiments, the method further comprises at least one of the following:
[0037] When the VPN function is enabled, obtain the VPN interface;
[0038] When the WiFi hotspot is turned on, the hotspot interface is obtained.
[0039] According to a second aspect of an embodiment of the present disclosure, a VPN sharing device is provided, the device comprising:
[0040] a prompt module configured to display a prompt message when monitoring that the target device is connected to a WiFi hotspot, wherein the prompt message is used to prompt whether to allow the target device to access a target VPN through the electronic device, wherein the target VPN is the VPN currently connected to the electronic device;
[0041] The access module is configured to allow the target device to access the target VPN through the electronic device in response to receiving the first feedback information.
[0042] In some embodiments, the prompt information is a prompt window, and the apparatus further includes:
[0043] a feedback information generating module, configured to generate the first feedback information in response to a triggering operation on the confirmation control; or
[0044] The feedback information generating module is further configured to generate second feedback information in response to a triggering operation on the denial control, where the second feedback information indicates that the target device is not allowed to access the target VPN through the electronic device.
[0045] In some embodiments, the prompt module is configured to display the prompt information when it is detected that the target device is connected to a WiFi hotspot and the electronic device has enabled a VPN sharing function.
[0046] In some embodiments, the apparatus further comprises:
[0047] A rule adding module is configured to add client rules when allowing the target device to access the target VPN through the electronic device. The client rules include at least routing rules. The routing rules are for forwarding data packets to the target VPN through the VPN interface. The data packets are received through the hotspot interface and the source IP address is a first address. The first address is the IP address of the target device.
[0048] In some embodiments, the client rule further includes at least one of the following:
[0049] Obtain the IP address of the hotspot interface;
[0050] Obtain the routing table number corresponding to the VPN interface;
[0051] Obtain the IP address of the target server set by the VPN interface;
[0052] The priority of the routing rule is higher than the priority of the original routing rule, and the original routing rule refers to the routing rule when the target device is connected to the WiFi hotspot and does not access the target VPN;
[0053] The destination IP address of the data packet is modified from the IP address of the hotspot interface to the IP address of the target server.
[0054] In some embodiments, the apparatus further comprises:
[0055] A rule adding module is configured to add an initialization rule when monitoring that the VPN function, the WiFi hotspot, and the VPN sharing function are enabled;
[0056] The initialization rules include at least one of the following:
[0057] Allowing data packets to be forwarded from the hotspot interface to the VPN interface;
[0058] Allowing data packets to be forwarded from the VPN interface to the hotspot interface;
[0059] The source IP address of the data packet sent from the VPN interface is modified to the IP address of the VPN interface.
[0060] In some embodiments, the apparatus further comprises:
[0061] a data sending module, configured to receive, based on the client rule, a first data packet sent by the target device through the hotspot interface, where the source IP address of the first data packet is the first address and the destination IP address of the first data packet is the IP address of the hotspot interface;
[0062] The data sending module is further configured to forward the first data packet from the hotspot interface to the VPN interface;
[0063] The data sending module is further configured to modify the destination IP address of the first data packet from the IP address of the hotspot interface to the IP address of the target server, and modify the source IP address of the first data packet from the first address to the IP address of the VPN interface;
[0064] The data sending module is further configured to send the modified first data packet to the target VPN.
[0065] In some embodiments, the apparatus further comprises:
[0066] The rule deletion module is configured to delete the added initialization rule and the client rule after the VPN sharing function is disabled.
[0067] In some embodiments, the apparatus further comprises at least one of the following:
[0068] A sharing function activation module is configured to activate the VPN sharing function when the WiFi hotspot is activated;
[0069] The sharing function closing module is configured to close the VPN sharing function while closing the WiFi hotspot.
[0070] In some embodiments, the apparatus further comprises at least one of the following:
[0071] The VPN interface acquisition module is configured to acquire the VPN interface when the VPN function is enabled;
[0072] The hotspot interface acquisition module is configured to acquire the hotspot interface when the WiFi hotspot is turned on.
[0073] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, including:
[0074] processor;
[0075] a memory for storing processor-executable instructions;
[0076] The processor is configured to execute the method as described in the first aspect of the embodiment of the present disclosure.
[0077] According to a fourth aspect of an embodiment of the present disclosure, a non-temporary computer-readable storage medium is provided, which, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to execute the method described in the first aspect of the embodiment of the present disclosure.
[0078] The above method of the present disclosure has the following beneficial effects:
[0079] The method provided by the embodiment of the present disclosure, when monitoring a target device connecting to a WiFi hotspot, indicates that the target device wants to access a target VPN currently connected to the electronic device, and at this time, a prompt message is displayed, the prompt message being used to prompt whether the target device is allowed to access the target VPN through the electronic device, and then in response to receiving first feedback information, the target device is allowed to access the target VPN through the electronic device, that is, the first feedback information indicates that the target device is allowed to access the target VPN through the electronic device, thereby realizing the function of the target device accessing the VPN through the electronic device, and enabling the electronic device to control whether the target device connected to the WiFi hotspot is allowed to access the VPN, thereby improving the security of the target device accessing the VPN through the electronic device.
[0080] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0081] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0082] Figure 1 A network architecture in which a target device accesses a VPN through an electronic device is shown according to an exemplary embodiment;
[0083] Figure 2 is a flow chart showing a VPN sharing method according to an exemplary embodiment;
[0084] Figure 3 is a flow chart showing another VPN sharing method according to an exemplary embodiment;
[0085] Figure 4 is a flowchart showing a process of monitoring WiFi hotspots according to an exemplary embodiment;
[0086] Figure 5 is a flow chart showing a process of monitoring a VPN function according to an exemplary embodiment;
[0087] Figure 6 is a schematic diagram showing a setting interface according to an exemplary embodiment;
[0088] Figure 7 is a schematic diagram showing a prompt window according to an exemplary embodiment;
[0089] Figure 8 is a flowchart showing a process of adding initialization rules according to an exemplary embodiment;
[0090] Figure 9 is a flowchart illustrating a process of adding client rules according to an exemplary embodiment;
[0091] Figure 10 is a block diagram showing a VPN sharing device according to an exemplary embodiment;
[0092] Figure 11 is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION
[0093] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, like numbers in different figures represent like or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments are not intended to represent all possible embodiments consistent with the present invention. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present invention, as detailed in the appended claims.
[0094] The VPN sharing method provided in the embodiment of the present disclosure is executed by an electronic device, such as a mobile phone, tablet computer, laptop computer, wearable device, etc. The electronic device can connect to a VPN and can share a WiFi hotspot.
[0095] See also Figure 1 The target device shown accesses the VPN network architecture through an electronic device, such as Figure 1 As shown, the network architecture includes an electronic device, a target device, a VPN server, and other devices in the VPN. The electronic device is a device that can open a WiFi hotspot, and the target device is a device that has a WiFi hotspot client installed. That is, the target device can connect to the WiFi hotspot of other devices. The target device is connected to the electronic device, and the electronic device is connected to the VPN.
[0096] based on Figure 1The network architecture shown in the figure shows that the VPN sharing method provided by the embodiment of the present disclosure can be applied in a variety of scenarios. Taking the electronic device as a mobile phone and the target device as a computer as an example, in the scenario where the computer accesses the VPN, the mobile phone is connected to the company's VPN. The computer does not have a VPN client and cannot directly connect to the company's VPN. In this case, the mobile phone shares the connected VPN through the WiFi hotspot, and the computer connects to the mobile phone's WiFi hotspot. When the mobile phone allows the computer to access the company's VPN, the computer accesses the company's VPN. Of course, it can also be applied in other scenarios.
[0097] Figure 2 is a flowchart of a VPN sharing method according to an exemplary embodiment, which is executed by an electronic device. Figure 2 , the method comprises the following steps:
[0098] Step S201: When it is detected that the target device is connected to a WiFi hotspot, a prompt message is displayed, where the prompt message is used to prompt whether to allow the target device to access the target VPN through the electronic device.
[0099] The target device is a device that can connect to a WiFi hotspot on other devices, such as a mobile phone, tablet, or laptop. When a WiFi hotspot is enabled on an electronic device, it acts as a wireless access point. The target device connects to the WiFi hotspot, establishing a communication connection with the electronic device through the WiFi hotspot. The target VPN is the VPN to which the electronic device is currently connected.
[0100] In the embodiment of the present disclosure, when the electronic device monitors that the target device is connected to the WiFi hotspot, it indicates that the target device wants to establish a communication connection with the electronic device. If a communication connection is established between the target device and the electronic device, the electronic device will share the connected target VPN with the target device, that is, enable the target device to send data to the VPN through the electronic device. In order to ensure the security of the target device, in this case, a prompt message is displayed, and the user can decide whether to allow the target device to access the target VPN through the electronic device as needed.
[0101] Step S202: In response to receiving the first feedback information, allowing the target device to access the target VPN through the electronic device.
[0102] The first feedback information indicates that the target device is allowed to access the target VPN through the electronic device. After the prompt information is displayed, the user performs a corresponding operation so that the electronic device receives the corresponding feedback information. When the electronic device receives the first feedback information, it is determined that the target device is allowed to access the target VPN through the electronic device.
[0103] The method provided by the embodiment of the present disclosure, when monitoring a target device connecting to a WiFi hotspot, indicates that the target device wants to access a target VPN currently connected to the electronic device, and at this time, a prompt message is displayed, the prompt message being used to prompt whether the target device is allowed to access the target VPN through the electronic device, and then in response to receiving first feedback information, the target device is allowed to access the target VPN through the electronic device, that is, the first feedback information indicates that the target device is allowed to access the target VPN through the electronic device, thereby realizing the function of the target device accessing the VPN through the electronic device, and enabling the electronic device to control whether the target device connected to the WiFi hotspot is allowed to access the VPN, thereby improving the security of the target device accessing the VPN through the electronic device.
[0104] Figure 3 is a flowchart of another VPN sharing method according to an exemplary embodiment, which is executed by an electronic device. Figure 3 , the method comprises the following steps:
[0105] Step S301: When the VPN function is enabled, a VPN interface is obtained; when the WiFi hotspot is enabled, a hotspot interface is obtained.
[0106] In the disclosed embodiments, when an electronic device enables its VPN function and connects to a target VPN, a VPN interface is generated. The electronic device can then communicate with the VPN server within the VPN through this VPN interface. The IP address of this VPN interface is the IP address of the electronic device within the VPN. Similarly, when an electronic device enables its WiFi function, a WiFi interface is generated.
[0107] In some embodiments, the setting interface in the electronic device is provided with a VPN function switch and a WiFi hotspot switch. When the VPN function needs to be turned on, the VPN function switch is turned on, and when the WiFi hotspot needs to be turned on, the WiFi hotspot switch is turned on.
[0108] In some embodiments, a VPN client is installed in the electronic device. After the VPN function is enabled, the electronic device communicates with the VPN server through the VPN client.
[0109] In some embodiments, see Figure 4 As shown in the flowchart of the process of monitoring WiFi hotspots, the electronic device first defines the name of the hotspot interface as ApIfaceName, and then the electronic device monitors whether the WiFi hotspot is turned on through the background service. When the WiFi hotspot is turned on, the hotspot interface is obtained and recorded, that is, the name of the hotspot interface is obtained and recorded as ApIfaceName. When the WiFi hotspot is not turned on, the electronic device continues to monitor whether the WiFi hotspot is turned on.
[0110] In some embodiments, see Figure 5 The flowchart of the process of monitoring the VPN function shown is as follows: first, the electronic device defines the name of the VPN interface as VpnIfaceName, and then the electronic device monitors whether the VPN interface is turned on through the background service. When the VPN function is turned on, the VPN interface is obtained and recorded, that is, the name of the VPN interface is obtained and recorded as VpnIfaceName. When the VPN function is not turned on, the electronic device continues to monitor whether the VPN function is turned on.
[0111] It should be noted that the embodiment of the present disclosure does not limit the order of enabling the VPN function and enabling the WiFi hotspot.
[0112] Step S302: Enable the VPN sharing function.
[0113] The VPN sharing function is used to share the VPN to which the electronic device is currently connected.
[0114] In some embodiments, when the WiFi hotspot is turned on, the VPN sharing function is turned on; when the WiFi hotspot is turned off, the VPN sharing function is turned off. That is, the VPN sharing function depends on the WiFi hotspot and can only be turned on when the WiFi hotspot is turned on. For example, see Figure 6 The schematic diagram of the settings interface shown is provided with a WiFi hotspot (WLAN hotspot) switch and a VPN sharing function (sharing VPN through the hotspot) switch. When the WiFi hotspot switch is turned on, the user can decide whether to turn on the VPN sharing function. When both the WiFi hotspot and VPN sharing functions are turned on, if the WiFi hotspot is turned off, the VPN sharing function is also turned off simultaneously.
[0115] In some embodiments, the VPN sharing function and the WiFi function are independent of each other, that is, whether the WiFi function is turned on or not does not affect the turning on of the VPN sharing function.
[0116] In some embodiments, the electronic device monitors whether the VPN sharing function is enabled through a background service. Optionally, the electronic device determines whether the VPN sharing function is enabled through broadcast, ContentObserver, or other IPC (Inter-Process Communication) mechanisms.
[0117] It should be noted that step S302 is an optional step. In another embodiment, it is not necessary to select whether to enable the VPN sharing function. When the VPN function and the WiFi hotspot are enabled, the electronic device determines that the VPN sharing function is enabled. When at least one of the VPN function and the WiFi hotspot is disabled, the electronic device determines that the VPN sharing function is disabled.
[0118] Step S303: When it is detected that the VPN function, WiFi hotspot, and VPN sharing function are enabled, an initialization rule is added.
[0119] In the embodiment of the present disclosure, in order to ensure secure communication between the electronic device and the VPN when the VPN function, WiFi hotspot, and VPN sharing function are enabled, it is necessary to add initialization rules to limit the data that can be forwarded between the electronic device and the VPN.
[0120] The initialization rules include at least one of the following: allowing data packets to be forwarded from the hotspot interface to the VPN interface; allowing data packets to be forwarded from the VPN interface to the hotspot interface; and modifying the source IP address of data packets sent from the VPN interface to the IP address of the VPN interface. This address translation process is called Source Network Address Translation (SNAT). This means that data packets are only allowed to be forwarded between the VPN interface and the hotspot interface, thereby preventing data packets received through other interfaces from being forwarded to the VPN interface.
[0121] Step S304: When it is detected that the target device is connected to a WiFi hotspot and the VPN sharing function is enabled on the electronic device, a prompt message is displayed.
[0122] In some embodiments, the prompt information is a prompt window, which includes a confirmation control and a denial control. After displaying the prompt information, the method also includes: generating first feedback information in response to a triggering operation on the confirmation control, and the first feedback information indicates that the target device is allowed to access the target VPN through the electronic device; or, generating second feedback information in response to a triggering operation on the denial control, and the second feedback information indicates that the target device is not allowed to access the target VPN through the electronic device.
[0123] For example, see Figure 7 Schematic diagram of the prompt window shown, when the target device is connected to a WiFi hotspot and the electronic device has turned on the VPN sharing function, the device name, MAC (Media Access Control) address, IP address and other information of the target device can be obtained, and the user is asked whether to allow the device to access the VPN. When the user selects "Yes", the first feedback information is generated, and when the user selects "No", the second feedback information is generated.
[0124] In some embodiments, the prompt information is a voice message, that is, displaying the prompt information includes: playing the voice message. Then, when a confirmation voice message is received from the user, first feedback information is generated, and when a denial voice message is received from the user, second feedback information is generated. The confirmation voice message indicates that the user allows the target device to access the target VPN through the electronic device, for example, the confirmation voice message is a voice message indicating affirmation such as "yes," "okay," or "can connect." The denial voice message indicates that the user does not allow the target device to access the target VPN through the electronic device, for example, the denial voice message is a voice message indicating denial such as "no," "cannot," or "cannot connect."
[0125] In some embodiments, the prompt information includes a prompt window and voice information, that is, while the prompt window is displayed, the voice information is played, and the user can operate in the prompt window or respond by voice, where the operation method and voice response method are the same as the above embodiment.
[0126] Of course, in some embodiments, the prompt information may also be in other forms, and the embodiments of the present disclosure are no longer limited here.
[0127] Step S305: In response to receiving the first feedback information, the target device is allowed to access the target VPN through the electronic device.
[0128] When the electronic device receives the first feedback information, it indicates that the target device is allowed to access the target VPN through the electronic device. In this case, in response to receiving the first feedback information, the target device is allowed to access the target VPN through the electronic device.
[0129] Step S306: When the target device is allowed to access the target VPN through the electronic device, a client rule is added.
[0130] In an embodiment of the present disclosure, when a target device is allowed to access a target VPN through an electronic device, in order to ensure the security of the target device when accessing the target VPN through the electronic device, a client rule is further added on the basis of the initialization rule. Among them, the client rule includes at least a routing rule, and the routing rule is to forward a data packet to the target VPN through the VPN interface. The data packet is a data packet received through the hotspot interface and the source IP address is a first address, and the first address is the IP address of the target device. In other words, the routing rule allows the data packet sent by the target device to the electronic device through the WiFi interface to be forwarded to the VPN interface, and thus sent to the target VPN.
[0131] In some embodiments, routing rules are configured through netlink, or through the ip rule command.
[0132] In some embodiments, the client rules also include at least one of the following: obtaining the IP address of the hotspot interface; obtaining the routing table number corresponding to the VPN interface, the routing table number is used to indicate the target VPN; obtaining the IP address of the target server set by the VPN interface, the target server is a server set by the VPN interface to provide DNS (Domain Name System) services, for example, the target server is a DNS server. The priority of the routing rule is higher than the priority of the original routing rule. The original routing rule refers to the routing rule when the target device is connected to the WiFi hotspot and has not accessed the target VPN, that is, it ensures that when the target device accesses the target VPN, the data packet sent by the target device can be forwarded to the target VPN instead of being sent to other interfaces or not being sent; the destination IP address of the data packet is modified from the IP address of the hotspot interface to the IP address of the target server. This address conversion process is called Destination Network Address Translation (DNAT).
[0133] In the embodiment of the present disclosure, the client rules further limit data forwarding only between the VPN interface and the hotspot interface based on the initialization rules, thereby improving the security of data transmission and avoiding sending data that the target device wants to send to the target VPN to other devices or other networks.
[0134] Step S307: forwarding data between the hotspot interface and the VPN interface based on the client rules.
[0135] In the embodiment of the present disclosure, after the client rules are added, the electronic device can forward data between the hotspot interface and the VPN interface based on the client rules, that is, send data packets sent by the target device between the hotspot interface and the VPN interface, or send data packets fed back by the target VPN.
[0136] In some embodiments, based on client rules, a first data packet sent by a target device is received through a hotspot interface, where the source IP address of the first data packet is the first address, and the destination IP address of the first data packet is the IP address of the hotspot interface, indicating that the first data packet is sent from the target device to the hotspot interface of the electronic device; the first data packet is forwarded from the hotspot interface to the VPN interface; the destination IP address of the first data packet is modified from the IP address of the hotspot interface to the IP address of the target server, and the source IP address of the first data packet is modified from the first address to the IP address of the VPN interface, i.e., the first data packet is modified to a data packet sent from the VPN interface to the target VPN; and the modified first data packet is sent to the target VPN.
[0137] In some embodiments, the electronic device receives a second data packet sent by the target VPN through a VPN interface, where the source IP address of the second data packet is the IP address of the target server, and the destination IP address of the second data packet is the IP address of the VPN interface; the second data packet is forwarded from the VPN interface to the hotspot interface; the destination IP address of the second data packet is modified from the IP address of the VPN interface to the first address, and the source IP address of the second data packet is modified from the IP address of the target server to the IP address of the hotspot interface.
[0138] It should be noted that after disabling the VPN sharing function, the added initialization rules and client rules are deleted. That is, after disabling the VPN sharing function, the target device no longer accesses the target VPN through the electronic device. In order to conserve the electronic device's storage resources, the added initialization rules and client rules are deleted. When a device accesses the VPN through the electronic device again, the initialization rules and client rules are re-added.
[0139] It should be noted that the embodiment of the present disclosure is only described using one target device as an example. In another embodiment, multiple target devices may access the target VPN through the electronic device at the same time, wherein the process of each target device accessing the target VPN is the same as the above embodiment.
[0140] The method provided by the embodiment of the present disclosure monitors that a target device is connected to a WiFi hotspot and the VPN sharing function is turned on, indicating that the target device wants to access the target VPN currently connected to the electronic device. At this time, a prompt message is displayed, and the prompt message is used to prompt whether the target device is allowed to access the target VPN through the electronic device. Then, in response to receiving first feedback information, the target device is allowed to access the target VPN through the electronic device. That is, the first feedback information indicates that the target device is allowed to access the target VPN through the electronic device. Therefore, while realizing the function of the target device accessing the VPN through the electronic device, the electronic device can control whether the target device connected to the WiFi hotspot is allowed to access the VPN, thereby improving the security of the target device accessing the VPN through the electronic device.
[0141] In some embodiments, see Figure 8 The flowchart of the initialization rule adding process shown in FIG. 1 includes the following steps:
[0142] 1. Monitor whether the VPN sharing function is triggered to be turned on / off.
[0143] 2. Determine whether the VPN sharing function is enabled. If the VPN sharing function is not enabled, that is, the VPN sharing function is closed, proceed to step 3. If the VPN sharing function is enabled, proceed to step 4.
[0144] 3. Delete the added rules and perform step 2 again.
[0145] 4. Monitor whether the WiFi hotspot and VPN functions are both enabled. If both are enabled, proceed to step 5. If both are enabled but at least one is not, repeat step 4.
[0146] 5. Add initialization rules, that is, add firewall rules: allow data packets to be forwarded from the hotspot interface to the VPN interface; allow data packets to be forwarded from the VPN interface to the hotspot interface; change the source IP address of the data packets sent from the VPN interface to the IP address of the VPN interface.
[0147] In some embodiments, see Figure 9 The flowchart of the client rule adding process shown in FIG. 1 includes the following steps:
[0148] 1. Define the IP address of the connected device as ClientIpAddr.
[0149] 2. Listen to see if there is a target device connected to the WiFi hotspot. If there is no target device connected to the WiFi hotspot, repeat step 2. If there is a target device connected to the WiFi hotspot, proceed to step 3.
[0150] 3. Determine whether the VPN sharing function is enabled. If the VPN sharing function is not enabled, the target device will only connect to the WiFi hotspot. If the VPN sharing function is enabled, proceed to step 4.
[0151] 4. Display a prompt pop-up window.
[0152] 5. Determine whether the target device is allowed to access the VPN. If the target device is not allowed to access the VPN, the target device only connects to the WiFi hotspot. If the target device is allowed to access the VPN, proceed to step 6.
[0153] 6. Obtain the IP address of the target device, that is, determine that the IP address of the target device is ClientIpAddr.
[0154] 7. Monitor whether the WiFi hotspot and VPN functions are both enabled. If both are enabled, proceed to step 8. If both are enabled but at least one is not, repeat step 7.
[0155] 8. Add client rules.
[0156] The client rules include: changing the destination IP address of the data packet from the IP address of the hotspot interface to the IP address of the target server
[0157] Get the IP address of the hotspot interface (AplpAddr), get the routing table number corresponding to the VPN interface (VpnRouteTable), and get the IP address of the target server set for the VPN interface (VpnDnsServer);
[0158] Add routing rules: forward the data packet from the hotspot interface (ApIfaceName) and with the source IP address of ClientIpAddrde by looking up the routing table number corresponding to the VPN interface, that is, forward the data packet to the target VPN through the VPN interface. The data packet is received through the hotspot interface and has the source IP address of the first address. The first address is the IP address of the target device, and the priority of this routing rule is higher than the priority of the routing rule originally shared by the system's hotspot. The routing rule originally shared by the system's hotspot is the above-mentioned original routing rule.
[0159] Add a firewall rule: Change the destination IP address of DNS packets sent by the target device to the hotspot interface to VpnDnsServer. The characteristics of this DNS packet are: it comes from the hotspot interface (ApIfaceName), the source IP address is ClientIpAddr, the destination IP address is the hotspot interface's IP address (AplpAddr), the destination port is 53, and it is a UDP (User Datagram Protocol) packet.
[0160] Figure 10 is a block diagram of a VPN sharing device according to an exemplary embodiment. Figure 10 , the device comprises:
[0161] The prompt module 1001 is configured to display a prompt message when monitoring that the target device is connected to a WiFi hotspot, the prompt message being used to prompt whether to allow the target device to access a target VPN through the electronic device, the target VPN being the VPN currently connected to the electronic device;
[0162] The access module 1002 is configured to allow the target device to access the target VPN through the electronic device in response to receiving the first feedback information.
[0163] The apparatus provided by the embodiment of the present disclosure, when monitoring that a target device is connected to a WiFi hotspot and the VPN sharing function is turned on, indicates that the target device wants to access the target VPN currently connected to the electronic device. At this time, a prompt message is displayed, and the prompt message is used to prompt whether the target device is allowed to access the target VPN through the electronic device. Thereafter, in response to receiving first feedback information, the target device is allowed to access the target VPN through the electronic device. That is, the first feedback information indicates that the target device is allowed to access the target VPN through the electronic device. Thus, while realizing the function of the target device accessing the VPN through the electronic device, the electronic device can control whether the target device connected to the WiFi hotspot is allowed to access the VPN, thereby improving the security of the target device accessing the VPN through the electronic device.
[0164] In some embodiments, the prompt information is a prompt window, and the device further includes:
[0165] A feedback information generating module is configured to generate first feedback information in response to a triggering operation on a confirmation control; or
[0166] The feedback information generating module is further configured to generate second feedback information in response to a triggering operation on the denial control, where the second feedback information indicates that the target device is not allowed to access the target VPN through the electronic device.
[0167] In some embodiments, the prompt module 1001 is configured to display a prompt message when it is detected that the target device is connected to a WiFi hotspot and the electronic device has enabled the VPN sharing function.
[0168] In some embodiments, the apparatus further comprises:
[0169] The rule adding module is configured to add client rules when allowing the target device to access the target VPN through the electronic device. The client rules include at least routing rules. The routing rules are for forwarding data packets to the target VPN through the VPN interface. The data packets are received through the hotspot interface and the source IP address is the first address. The first address is the IP address of the target device.
[0170] In some embodiments, the client rule further includes at least one of the following:
[0171] Get the IP address of the hotspot interface;
[0172] Get the routing table number corresponding to the VPN interface;
[0173] Get the IP address of the target server set by the VPN interface;
[0174] The priority of the routing rule is higher than the priority of the original routing rule. The original routing rule refers to the routing rule when the target device is connected to the WiFi hotspot and has not accessed the target VPN.
[0175] Change the destination IP address of the data packet from the IP address of the hotspot interface to the IP address of the target server.
[0176] In some embodiments, the apparatus further comprises:
[0177] A rule adding module is configured to add initialization rules when detecting that the VPN function, WiFi hotspot, and VPN sharing function are enabled;
[0178] The initialization rules include at least one of the following:
[0179] Allow packets to be forwarded from the hotspot interface to the VPN interface;
[0180] Allow packets to be forwarded from the VPN interface to the hotspot interface;
[0181] Change the source IP address of packets sent from the VPN interface to the IP address of the VPN interface.
[0182] In some embodiments, the apparatus further comprises:
[0183] a data sending module configured to receive, based on a client rule, a first data packet sent by a target device through a hotspot interface, wherein a source IP address of the first data packet is the first address and a destination IP address of the first data packet is the IP address of the hotspot interface;
[0184] The data sending module is further configured to forward the first data packet from the hotspot interface to the VPN interface;
[0185] The data sending module is further configured to modify the destination IP address of the first data packet from the IP address of the hotspot interface to the IP address of the target server, and to modify the source IP address of the first data packet from the first address to the IP address of the VPN interface;
[0186] The data sending module is further configured to send the modified first data packet to the target VPN.
[0187] In some embodiments, the apparatus further comprises:
[0188] The rule deletion module is configured to delete the added initialization rules and client rules after the VPN sharing function is disabled.
[0189] In some embodiments, the apparatus further comprises at least one of the following:
[0190] The sharing function activation module is configured to enable the VPN sharing function when the WiFi hotspot is turned on;
[0191] The sharing function disabling module is configured to disable the VPN sharing function while disabling the WiFi hotspot.
[0192] In some embodiments, the apparatus further comprises at least one of the following:
[0193] The VPN interface acquisition module is configured to acquire the VPN interface when the VPN function is enabled;
[0194] The hotspot interface acquisition module is configured to obtain the hotspot interface when the WiFi hotspot is turned on.
[0195] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0196] An embodiment of the present disclosure further provides an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to execute the VPN sharing method in the above embodiment.
[0197] Figure 11 is a block diagram of an electronic device 1100 according to an exemplary embodiment.
[0198] Reference Figure 11 , the electronic device 1100 may include one or more of the following components: a processing component 1102 , a memory 1104 , a power component 1106 , a multimedia component 1108 , an audio component 1110 , an input / output (I / O) interface 1112 , a sensor component 1114 , and a communication component 1116 .
[0199] The processing component 1102 generally controls the overall operation of the electronic device 1100, such as operations associated with display, phone calls, data communications, camera operation, and recording operations. The processing component 1102 may include one or more processors 1120 to execute instructions to perform all or part of the steps of the above-described method. In addition, the processing component 1102 may include one or more modules to facilitate interaction between the processing component 1102 and other components. For example, the processing component 1102 may include a multimedia module to facilitate interaction between the multimedia component 1108 and the processing component 1102.
[0200] The memory 1104 is configured to store various types of data to support operations on the electronic device 1100. Examples of such data include instructions for any application or method operating on the electronic device 1100, contact data, phone book data, messages, pictures, videos, etc. The memory 1104 can be implemented by any type of volatile or non-volatile storage device, or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk, or optical disk.
[0201] The power supply component 1106 provides power to the various components of the electronic device 1100. The power supply component 1106 may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the electronic device 1100.
[0202] The multimedia component 1108 includes a screen that provides an output interface between the electronic device 1100 and the user. In some embodiments, the screen may include a liquid crystal display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen may be implemented as a touch screen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, slides, and gestures on the touch panel. The touch sensor can not only sense the boundaries of the touch or slide action, but also detect the duration and pressure associated with the touch or slide operation. In some embodiments, the multimedia component 1108 includes a front camera and / or a rear camera. When the electronic device 1100 is in an operating mode, such as a shooting mode or a video mode, the front camera and / or the rear camera can receive external multimedia data. Each front camera and rear camera can be a fixed optical lens system or have a focal length and optical zoom capability.
[0203] The audio component 1110 is configured to output and / or input audio signals. For example, the audio component 1110 includes a microphone (MIC), which is configured to receive external audio signals when the electronic device 1100 is in an operating mode, such as a call mode, a recording mode, and a voice recognition mode. The received audio signal can be further stored in the memory 1104 or transmitted via the communication component 1116. In some embodiments, the audio component 1110 also includes a speaker for outputting audio signals.
[0204] I / O interface 1112 provides an interface between processing component 1102 and peripheral interface modules, such as a keyboard, click wheel, buttons, etc. These buttons may include but are not limited to: a home button, volume buttons, a start button, and a lock button.
[0205] The sensor assembly 1114 includes one or more sensors for providing various aspects of the status assessment of the electronic device 1100. For example, the sensor assembly 1114 can detect the open / closed state of the electronic device 1100, the relative positioning of components, such as the display and keypad of the electronic device 1100. The sensor assembly 1114 can also detect changes in the position of the electronic device 1100 or a component of the electronic device 1100, the presence or absence of user contact with the electronic device 1100, the orientation or acceleration / deceleration of the electronic device 1100, and changes in the temperature of the electronic device 1100. The sensor assembly 1114 can include a proximity sensor configured to detect the presence of nearby objects without any physical contact. The sensor assembly 1114 can also include an optical sensor, such as a CMOS or CCD image sensor, for use in imaging applications. In some embodiments, the sensor assembly 1114 can also include an accelerometer, a gyroscope, a magnetic sensor, a pressure sensor, or a temperature sensor.
[0206] The communication component 1116 is configured to facilitate wired or wireless communication between the electronic device 1100 and other devices. The electronic device 1100 can access a wireless network based on a communication standard, such as WiFi, 2G or 3G, or a combination thereof. In an exemplary embodiment, the communication component 1116 receives a broadcast signal or broadcast-related information from an external broadcast management system via a broadcast channel. In an exemplary embodiment, the communication component 1116 also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra-wideband (UWB) technology, Bluetooth (BT) technology and other technologies.
[0207] In an exemplary embodiment, the electronic device 1100 may be implemented by one or more application-specific integrated circuits (ASICs), digital signal processors (DSPs), digital signal processing devices (DSPDs), programmable logic devices (PLDs), field programmable gate arrays (FPGAs), controllers, microcontrollers, microprocessors, or other electronic components to perform the above-described methods.
[0208] In an exemplary embodiment, a non-transitory computer-readable storage medium including instructions is also provided, such as a memory 1104 including instructions, and the instructions can be executed by the processor 1120 of the electronic device 1100 to perform the above method. For example, the non-transitory computer-readable storage medium can be a ROM, a random access memory (RAM), a CD-ROM, a magnetic tape, a floppy disk, an optical data storage device, etc.
[0209] The embodiments of the present disclosure further provide a non-transitory computer-readable storage medium. When instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the VPN sharing method in the above embodiment.
[0210] Other embodiments of the present invention will readily occur to those skilled in the art after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The description and examples are to be considered as exemplary only, with the true scope and spirit of the invention being indicated by the following claims.
[0211] It should be understood that the present invention is not limited to the exact construction described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present invention is limited only by the appended claims.
Claims
1. A VPN sharing method, characterized in that: The method comprises: When monitoring that the target device is connected to a WiFi hotspot, displaying a prompt message, the prompt message is used to prompt whether to allow the target device to access a target VPN through the electronic device, the target VPN being the VPN currently connected to the electronic device; In response to receiving the first feedback information, the target device is allowed to access the target VPN through the electronic device.
2. The method according to claim 1, characterized in that The prompt information is a prompt window, and the prompt window includes a confirmation control and a denial control. After displaying the prompt information, the method further includes: In response to a triggering operation on the confirmation control, generating the first feedback information; or, In response to the triggering operation of the denial control, second feedback information is generated, wherein the second feedback information indicates that the target device is not allowed to access the target VPN through the electronic device.
3. The method according to claim 1, characterized in that When the target device is detected to be connected to a WiFi hotspot, a prompt message is displayed, including: When it is monitored that the target device is connected to a WiFi hotspot and the VPN sharing function of the electronic device is turned on, the prompt information is displayed.
4. The method according to claim 3, characterized in that The method further comprises: When the target device is allowed to access the target VPN through the electronic device, client rules are added, and the client rules include at least routing rules. The routing rules are for forwarding data packets to the target VPN through the VPN interface. The data packets are data packets received through the hotspot interface and the source IP address is a first address. The first address is the IP address of the target device.
5. The method according to claim 4, characterized in that The client rules also include at least one of the following: Obtain the IP address of the hotspot interface; Obtaining the routing table number corresponding to the VPN interface; Obtain the IP address of the target server set by the VPN interface; The priority of the routing rule is higher than the priority of the original routing rule, and the original routing rule refers to the routing rule when the target device is connected to the WiFi hotspot and does not access the target VPN; The destination IP address of the data packet is modified from the IP address of the hotspot interface to the IP address of the target server.
6. The method according to claim 5, characterized in that The method further comprises: When monitoring that the VPN function, the WiFi hotspot, and the VPN sharing function are turned on, add initialization rules; The initialization rule includes at least one of the following: Allowing data packets to be forwarded from the hotspot interface to the VPN interface; Allowing data packets to be forwarded from the VPN interface to the hotspot interface; The source IP address of the data packet sent from the VPN interface is modified to the IP address of the VPN interface.
7. The method according to claim 6, characterized in that The method further comprises: Based on the client rule, receiving a first data packet sent by the target device through the hotspot interface, the source IP address of the first data packet is the first address, and the destination IP address of the first data packet is the IP address of the hotspot interface; forwarding the first data packet from the hotspot interface to the VPN interface; Modify the destination IP address of the first data packet from the IP address of the hotspot interface to the IP address of the target server, and modify the source IP address of the first data packet from the first address to the IP address of the VPN interface; The modified first data packet is sent to the target VPN.
8. The method according to claim 6, characterized in that The method further comprises: After the VPN sharing function is turned off, the added initialization rules and the client rules are deleted.
9. The method according to any one of claims 3 to 8, characterized in that: The method further comprises at least one of the following: When the WiFi hotspot is turned on, the VPN sharing function is turned on; When the WiFi hotspot is turned off, the VPN sharing function is turned off.
10. The method according to any one of claims 3 to 8, characterized in that: The method further comprises at least one of the following: When the VPN function is enabled, obtain the VPN interface; When the WiFi hotspot is turned on, the hotspot interface is obtained.
11. A VPN sharing device, characterized in that: The device comprises: A prompt module is configured to display a prompt message when monitoring that the target device is connected to a WiFi hotspot, wherein the prompt message is used to prompt whether to allow the target device to access a target VPN through the electronic device, wherein the target VPN is the VPN currently connected to the electronic device; The access module is configured to allow the target device to access the target VPN through the electronic device in response to receiving the first feedback information.
12. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor is configured to execute the method according to any one of claims 1 to 10.
13. A non-transitory computer-readable storage medium, characterized in that: When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method as claimed in any one of claims 1 to 10.
