2dust / v2rayN

A GUI client for Windows, support Xray core and v2fly core and others
https://1.2345345.xyz
GNU General Public License v3.0
67.22k stars 11.21k forks source link

[Bug]: 新版v2rayN开启tun模式不创建虚拟网卡。tun模式开启后,节点真链接为-1ms。 #4101

Closed ZZXIXI closed 8 months ago

ZZXIXI commented 1 year ago

预期情况

tun模式无法一次开启,虚拟网卡无法创建

实际情况

开启tun模式后虚拟网卡无法创建,并且服务器节点真链接延迟变为-1 ms 启动服务(2023/7/18 1:24:04)... 2023/7/18 1:24:05 系统代理设置改变ForcedClear 2023/7/18 1:24:17 当前服务的真连接延迟: -1 ms FATAL[0016] start service: initialize inbound/tun[tun-in]: configure tun interface: Cannot create a file when that file already exists.

复现方法

选定可用服务器节点,开启tun模式

日志信息

[31mFATAL[0016] start service: initialize inbound/tun[tun-in]: configure tun interface: Cannot create a file when that file already exists.

额外信息

No response

我确认已更新至最新版本

我确认已查询历史issues

Kikyo-chan commented 1 year ago

我使用v2rayN 6.27版本,操作系统是Windows 10 22h2,并且打2023年7月最新补丁,tun模式是正常的。有以下建议参考: 1.换台Windows10下测试一下看看,也许有惊喜。 2.请以管理员权限运行“v2rayN.exe”,我刚开始没用管理员运行v2rayN.exe,界面“启用Tun模式”按钮始终不出来,最后我就点了以管理员权限运行试了下,就可以了,并且虚拟网卡也出来了(这个方法可以多次两次,有时singbox_tun虚拟网卡会出不来的情况) 3.我看到singbox_tun网卡启动后,分配了一个固定IP 172.19.0.1和172.17.0.2,虽然我不懂为什么Tun模式下会使用这两个IP地址,但是我也建议你看看,你当前的网络中是否有IP冲突。

image

image

image

yzy613 commented 1 year ago

4100

wenke313 commented 1 year ago

image 我的这解决了

gdnre commented 1 year ago

我也是发现用6.28版本的包里的文件开tun模式不会创建虚拟网卡,去检查更新里更新sing-box core后就可以开tun模式了

Totoro-Li commented 1 year ago
private void RemoveTunDevice()
        {
            string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe
            string searchID = "wintun"; // the ID to search for

            // Find the device
            ProcessStartInfo findStartInfo = new ProcessStartInfo
            {
                FileName = devconPath,
                Arguments = $"findall *{searchID}*",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process findProcess = new Process { StartInfo = findStartInfo };
            findProcess.Start();

            string output = findProcess.StandardOutput.ReadToEnd();
            findProcess.WaitForExit();

            Console.WriteLine("Find command output:");
            Console.WriteLine(output);

            // Extract the full hardware ID from the output
            string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

            if (!string.IsNullOrEmpty(fullDeviceID))
            {
                // Device found, remove it
                ProcessStartInfo removeStartInfo = new ProcessStartInfo
                {
                    FileName = devconPath,
                    Arguments = $"remove \"@{fullDeviceID}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                Process removeProcess = new Process { StartInfo = removeStartInfo };
                removeProcess.Start();

                string removeOutput = removeProcess.StandardOutput.ReadToEnd();
                removeProcess.WaitForExit();
                Console.WriteLine(removeOutput);
            }
        }

        private void DoEnableTun(bool c)
        {
            if (_config.tunModeItem.enableTun != EnableTun)
            {
                _config.tunModeItem.enableTun = EnableTun;
                RemoveTunDevice();
                Reload();
            }
        }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

Zhopeful88 commented 1 year ago
private void RemoveTunDevice()
        {
            string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe
            string searchID = "wintun"; // the ID to search for

            // Find the device
            ProcessStartInfo findStartInfo = new ProcessStartInfo
            {
                FileName = devconPath,
                Arguments = $"findall *{searchID}*",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process findProcess = new Process { StartInfo = findStartInfo };
            findProcess.Start();

            string output = findProcess.StandardOutput.ReadToEnd();
            findProcess.WaitForExit();

            Console.WriteLine("Find command output:");
            Console.WriteLine(output);

            // Extract the full hardware ID from the output
            string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

            if (!string.IsNullOrEmpty(fullDeviceID))
            {
                // Device found, remove it
                ProcessStartInfo removeStartInfo = new ProcessStartInfo
                {
                    FileName = devconPath,
                    Arguments = $"remove \"@{fullDeviceID}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                Process removeProcess = new Process { StartInfo = removeStartInfo };
                removeProcess.Start();

                string removeOutput = removeProcess.StandardOutput.ReadToEnd();
                removeProcess.WaitForExit();
                Console.WriteLine(removeOutput);
            }
        }

        private void DoEnableTun(bool c)
        {
            if (_config.tunModeItem.enableTun != EnableTun)
            {
                _config.tunModeItem.enableTun = EnableTun;
                RemoveTunDevice();
                Reload();
            }
        }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

我加入了您这个,编译后生成,还是不一样不行,不生成虚拟网卡,tun模式也不生效,连日志都没输出

Zhopeful88 commented 1 year ago
private void RemoveTunDevice()
        {
            string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe
            string searchID = "wintun"; // the ID to search for

            // Find the device
            ProcessStartInfo findStartInfo = new ProcessStartInfo
            {
                FileName = devconPath,
                Arguments = $"findall *{searchID}*",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process findProcess = new Process { StartInfo = findStartInfo };
            findProcess.Start();

            string output = findProcess.StandardOutput.ReadToEnd();
            findProcess.WaitForExit();

            Console.WriteLine("Find command output:");
            Console.WriteLine(output);

            // Extract the full hardware ID from the output
            string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

            if (!string.IsNullOrEmpty(fullDeviceID))
            {
                // Device found, remove it
                ProcessStartInfo removeStartInfo = new ProcessStartInfo
                {
                    FileName = devconPath,
                    Arguments = $"remove \"@{fullDeviceID}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                Process removeProcess = new Process { StartInfo = removeStartInfo };
                removeProcess.Start();

                string removeOutput = removeProcess.StandardOutput.ReadToEnd();
                removeProcess.WaitForExit();
                Console.WriteLine(removeOutput);
            }
        }

        private void DoEnableTun(bool c)
        {
            if (_config.tunModeItem.enableTun != EnableTun)
            {
                _config.tunModeItem.enableTun = EnableTun;
                RemoveTunDevice();
                Reload();
            }
        }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

wsarecv: An existing connection was forcibly closed by the remote host. 报这个错

Totoro-Li commented 1 year ago
private void RemoveTunDevice()
        {
            string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe
            string searchID = "wintun"; // the ID to search for

            // Find the device
            ProcessStartInfo findStartInfo = new ProcessStartInfo
            {
                FileName = devconPath,
                Arguments = $"findall *{searchID}*",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process findProcess = new Process { StartInfo = findStartInfo };
            findProcess.Start();

            string output = findProcess.StandardOutput.ReadToEnd();
            findProcess.WaitForExit();

            Console.WriteLine("Find command output:");
            Console.WriteLine(output);

            // Extract the full hardware ID from the output
            string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

            if (!string.IsNullOrEmpty(fullDeviceID))
            {
                // Device found, remove it
                ProcessStartInfo removeStartInfo = new ProcessStartInfo
                {
                    FileName = devconPath,
                    Arguments = $"remove \"@{fullDeviceID}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                Process removeProcess = new Process { StartInfo = removeStartInfo };
                removeProcess.Start();

                string removeOutput = removeProcess.StandardOutput.ReadToEnd();
                removeProcess.WaitForExit();
                Console.WriteLine(removeOutput);
            }
        }

        private void DoEnableTun(bool c)
        {
            if (_config.tunModeItem.enableTun != EnableTun)
            {
                _config.tunModeItem.enableTun = EnableTun;
                RemoveTunDevice();
                Reload();
            }
        }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

wsarecv: An existing connection was forcibly closed by the remote host. 报这个错

和我说的问题无关

Zhopeful88 commented 1 year ago
private void RemoveTunDevice()
        {
            string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe
            string searchID = "wintun"; // the ID to search for

            // Find the device
            ProcessStartInfo findStartInfo = new ProcessStartInfo
            {
                FileName = devconPath,
                Arguments = $"findall *{searchID}*",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process findProcess = new Process { StartInfo = findStartInfo };
            findProcess.Start();

            string output = findProcess.StandardOutput.ReadToEnd();
            findProcess.WaitForExit();

            Console.WriteLine("Find command output:");
            Console.WriteLine(output);

            // Extract the full hardware ID from the output
            string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

            if (!string.IsNullOrEmpty(fullDeviceID))
            {
                // Device found, remove it
                ProcessStartInfo removeStartInfo = new ProcessStartInfo
                {
                    FileName = devconPath,
                    Arguments = $"remove \"@{fullDeviceID}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                Process removeProcess = new Process { StartInfo = removeStartInfo };
                removeProcess.Start();

                string removeOutput = removeProcess.StandardOutput.ReadToEnd();
                removeProcess.WaitForExit();
                Console.WriteLine(removeOutput);
            }
        }

        private void DoEnableTun(bool c)
        {
            if (_config.tunModeItem.enableTun != EnableTun)
            {
                _config.tunModeItem.enableTun = EnableTun;
                RemoveTunDevice();
                Reload();
            }
        }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

wsarecv: An existing connection was forcibly closed by the remote host. 报这个错

和我说的问题无关

一开始就是提示这个: Cannot create a file when that file already exists. 我用您的代码在6.28版本加入编译后就时不时提上面那我截图的log,还是跟之前一样,开Tun多次才能成功一次,要么开了tun,很多网站都不走代理了,关了就好了

Totoro-Li commented 1 year ago
private void RemoveTunDevice()
        {
            string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe
            string searchID = "wintun"; // the ID to search for

            // Find the device
            ProcessStartInfo findStartInfo = new ProcessStartInfo
            {
                FileName = devconPath,
                Arguments = $"findall *{searchID}*",
                RedirectStandardOutput = true,
                UseShellExecute = false,
                CreateNoWindow = true
            };

            Process findProcess = new Process { StartInfo = findStartInfo };
            findProcess.Start();

            string output = findProcess.StandardOutput.ReadToEnd();
            findProcess.WaitForExit();

            Console.WriteLine("Find command output:");
            Console.WriteLine(output);

            // Extract the full hardware ID from the output
            string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

            if (!string.IsNullOrEmpty(fullDeviceID))
            {
                // Device found, remove it
                ProcessStartInfo removeStartInfo = new ProcessStartInfo
                {
                    FileName = devconPath,
                    Arguments = $"remove \"@{fullDeviceID}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true
                };

                Process removeProcess = new Process { StartInfo = removeStartInfo };
                removeProcess.Start();

                string removeOutput = removeProcess.StandardOutput.ReadToEnd();
                removeProcess.WaitForExit();
                Console.WriteLine(removeOutput);
            }
        }

        private void DoEnableTun(bool c)
        {
            if (_config.tunModeItem.enableTun != EnableTun)
            {
                _config.tunModeItem.enableTun = EnableTun;
                RemoveTunDevice();
                Reload();
            }
        }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

wsarecv: An existing connection was forcibly closed by the remote host. 报这个错

和我说的问题无关

一开始就是提示这个: Cannot create a file when that file already exists. 我用您的代码在6.28版本加入编译后就时不时提上面那我截图的log,还是跟之前一样,开Tun多次才能成功一次,要么开了tun,很多网站都不走代理了,关了就好了

这里的Devcon路径需要替换成你自己的Devcon(这个Windows 10不自带,另外下Windows Kits),或者改成用pnputil

Zhopeful88 commented 1 year ago

谢谢,我测试一下,昨晚编译的时候没有注意这个点

从 Windows 版邮件https://go.microsoft.com/fwlink/?LinkId=550986发送

发件人: @.> 发送时间: 2023年8月14日 8:54 收件人: @.> 抄送: @.>; @.> 主题: Re: [2dust/v2rayN] [Bug]: 新版v2rayN开启tun模式不创建虚拟网卡。tun模式开启后,节点真链接为-1ms。 (Issue #4101)

private void RemoveTunDevice()

    {

        string devconPath = @"C:\Program Files\ASUS\Armoury Crate Service Core\devcon.exe"; // path to devcon.exe

        string searchID = "wintun"; // the ID to search for

        // Find the device

        ProcessStartInfo findStartInfo = new ProcessStartInfo

        {

            FileName = devconPath,

            Arguments = $"findall *{searchID}*",

            RedirectStandardOutput = true,

            UseShellExecute = false,

            CreateNoWindow = true

        };

        Process findProcess = new Process { StartInfo = findStartInfo };

        findProcess.Start();

        string output = findProcess.StandardOutput.ReadToEnd();

        findProcess.WaitForExit();

        Console.WriteLine("Find command output:");

        Console.WriteLine(output);

        // Extract the full hardware ID from the output

        string fullDeviceID = new Regex(@"(.*):\s").Match(output).Groups[1].Value.Trim();

        if (!string.IsNullOrEmpty(fullDeviceID))

        {

            // Device found, remove it

            ProcessStartInfo removeStartInfo = new ProcessStartInfo

            {

                FileName = devconPath,

                Arguments = $"remove \"@{fullDeviceID}\"",

                RedirectStandardOutput = true,

                UseShellExecute = false,

                CreateNoWindow = true

            };

            Process removeProcess = new Process { StartInfo = removeStartInfo };

            removeProcess.Start();

            string removeOutput = removeProcess.StandardOutput.ReadToEnd();

            removeProcess.WaitForExit();

            Console.WriteLine(removeOutput);

        }

    }

    private void DoEnableTun(bool c)

    {

        if (_config.tunModeItem.enableTun != EnableTun)

        {

            _config.tunModeItem.enableTun = EnableTun;

            RemoveTunDevice();

            Reload();

        }

    }

singbox的开发者给的workaround是直接每次取一个新的tun设备名称,其实还是退出时没清理干净设备。一个简单的Fix就是开启tun时直接删了现有wintun设备再开。但是考虑到DevCon不是每个人电脑上都有,所以就不PR了,发在这里做一个参考

wsarecv: An existing connection was forcibly closed by the remote host. 报这个错

和我说的问题无关

一开始就是提示这个: Cannot create a file when that file already exists. 我用您的代码在6.28版本加入编译后就时不时提上面那我截图的log,还是跟之前一样,开Tun多次才能成功一次,要么开了tun,很多网站都不走代理了,关了就好了

这里的Devcon路径需要替换成你自己的Devcon(这个Windows 10不自带,另外下Windows Kits),或者改成用pnputil

― Reply to this email directly, view it on GitHubhttps://github.com/2dust/v2rayN/issues/4101#issuecomment-1676523318, or unsubscribehttps://github.com/notifications/unsubscribe-auth/BB3QRUBWFUWVPDPNLDHRQF3XVFZODANCNFSM6AAAAAA2NIKSDI. You are receiving this because you commented.Message ID: @.***>

WwwZMing commented 11 months ago

我也是发现用6.28版本的包里的文件开tun模式不会创建虚拟网卡,去检查更新里更新sing-box core后就可以开tun模式了

应该是正解,刚刚试了下成功了,也能正常读取规则,另外这个方法在低于6.2版本的时候用会出现tun规则无效的问题

mohalikeyou commented 9 months ago

我也是发现用6.28版本的包里的文件开tun模式不会创建虚拟网卡,去检查更新里更新sing-box core后就可以开tun模式了

更新完,TUN就开启了,感谢

bluesyk commented 8 months ago

我也是发现用6.28版本的包里的文件开tun模式不会创建虚拟网卡,去检查更新里更新sing-box core后就可以开tun模式了

--V6.29版本同样的问题,已经使用管理员运行,更新sing-box core后问题解决。

Hyman00 commented 8 months ago

我也是发现用6.28版本的包里的文件开tun模式不会创建虚拟网卡,去检查更新里更新sing-box core后就可以开tun模式了

--V6.29版本同样的问题,已经使用管理员运行,更新sing-box core后问题解决。

我用的是v6.33版本,更新完sing-box core后,还是有问题,这个是什么原因呢?

2dust commented 7 months ago

https://github.com/2dust/v2rayN/discussions/4683 此版本中增加了RemoveTunDevice,有需要的测试反馈下

AelecTi commented 6 months ago

设备管理器->顶部菜单栏“查看”->勾选“显示隐藏的设备”->下面“网络适配器”->找到并删除所有“sing-tun Tunnel”(勾选“删除驱动设备)

明显是一个"it works on my machine"的问题,开发者没有测试过老版本的Windows系统,以为在自己的系统上能跑就万事大吉。然而至少在Windows10 1909上,虚拟网卡设备卸载的并不彻底,甚至强行开TUN还会触发V2RayN某个神奇的内存溢出bug。不过对于一个翻墙软件也不能要求太多就是了