Overcoming Obstacles: Solutions for Remotely Connecting to Internet Computers in a Local Area Network (with multilingual connection tutorials)

I. Introduction

In this tutorial, we will introduce in detail how to remotely connect to a computer with Internet on a LAN computer when the LAN and Internet computers do not communicate with each other. We will discuss how to use third-party software (such as TeamViewer, AnyDesk, etc.) and the remote desktop function of the computer to realize remote connection. We'll walk through the process step by step so you can easily connect remotely.
insert image description here

2. Preparation

  1. Make sure that both the LAN computer and the Internet computer have installed remote desktop software (such as TeamViewer, AnyDesk, etc.), or enabled the remote desktop function that comes with the operating system (such as Windows remote desktop connection).
  2. Get the unique identifier of the computer on the Internet (such as TeamViewerID, AnyDesk address, etc.), or the computer name/IP address (for Windows Remote Desktop Connection).

3. Build a transit server

Since the computers on the LAN and the Internet cannot communicate with each other, we need to build a transit server to realize the connection. You can choose one of the following methods:

  1. Use VPS or cloud server: Purchase a VPS or cloud server with a public IP address, such as AWS, Alibaba Cloud, Tencent Cloud, etc.

  2. Take advantage of home broadband: If you have a home broadband, you can set it up as a relay server. This requires certain network knowledge, such as port mapping, DDNS settings, etc.

4. Configure the transit server

  1. Install VPN software (such as OpenVPN, SoftEther, etc.) on the transit server.
  2. Configure VPN software to allow LAN computers and Internet computers to connect to the same virtual network.
  3. Install the VPN client on the LAN computer and the Internet computer respectively, and configure the VPN service connected to the transit server.

After configuring the transfer server, you can use the language library to connect. Here I provide you with three commonly used languages: Python, Java, and C#. You can connect according to the language you know.

  1. Python code:
import paramiko

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

# 使用中转服务器的VPN IP地址和登录凭据进行连接
ssh.connect("中转服务器的VPN_IP地址", username="用户名", password="密码")

# 远程执行命令,比如启动远程桌面服务
stdin, stdout, stderr = ssh.exec_command("远程桌面服务启动命令")
  1. Java code:
import com.jcraft.jsch.*;

public class RemoteConnection {
    
    
    public static void main(String[] args) {
    
    
        try {
    
    
            JSch jsch = new JSch();

            // 使用中转服务器的VPN IP地址和登录凭据进行连接
            Session session = jsch.getSession("用户名", "中转服务器的VPN_IP地址", 22);
            session.setPassword("密码");
            session.setConfig("StrictHostKeyChecking", "no");
            session.connect();

            // 远程执行命令,比如启动远程桌面服务
            ChannelExec channel = (ChannelExec) session.openChannel("exec");
            channel.setCommand("远程桌面服务启动命令");
            channel.connect();

        } catch (JSchException e) {
    
    
            e.printStackTrace();
        }
    }
}
  1. C# code:
using Renci.SshNet;

public class RemoteConnection
{
    
    
    public static void Main(string[] args)
    {
    
    
        // 使用中转服务器的VPN IP地址和登录凭据进行连接
        var connectionInfo = new ConnectionInfo("中转服务器的VPN_IP地址", "用户名", new PasswordAuthenticationMethod("用户名", "密码"));
        using (var sshClient = new SshClient(connectionInfo))
        {
    
    
            sshClient.Connect();

            // 远程执行命令,比如启动远程桌面服务
            using (var cmd = sshClient.CreateCommand("远程桌面服务启动命令"))
            {
    
    
                cmd.Execute();
            }

            sshClient.Disconnect();
        }
    }
}

If you know the language library, you can refer to the above code to connect. If you use other libraries, you can leave a message in the comment area and leave the language you use. If you don’t know the code, you can skip it directly. For this step, just look down

5. Establish a connection

  1. Start the VPN client on the LAN computer and the Internet computer, and connect to the VPN service of the transit server.

  2. Make sure that the LAN computer and the Internet computer have joined the same virtual network.

  3. Start the remote desktop software on the LAN computer, enter the unique identifier of the Internet computer, and establish a remote connection. For Windows Remote Desktop Connection, enter the computer name or IP address.

Six, practical skills

  1. In order to improve the speed and stability of remote connections, please choose a VPS or cloud server close to your area.

  2. When using remote desktop software, close unnecessary applications to reduce the consumption of network resources.

  3. To keep your connection secure, make sure to use strong passwords and enable two-factor authentication, especially on VPN and remote desktop software.

  4. Regularly check and update your remote desktop software and VPN software for the latest security updates and feature improvements.

  5. When encountering a problem, try restarting the software or the computer, sometimes a simple restart can solve the problem.

6. Conclusion

Through the above steps, you should have successfully realized the remote connection between the LAN computer and the Internet computer. Keep in mind that while we've discussed how to do this in this tutorial, different environments may require different configurations. Therefore, you may need to adjust according to the actual situation. Always be mindful of your online security and make sure you have proper protection in place when using remote desktop and VPN services. I wish you a happy use!

Supongo que te gusta

Origin blog.csdn.net/tuzajun/article/details/130519004
Recomendado
Clasificación