问题描述
我正在使用C#通过openvpn连接远程服务器。我能够成功地连接它。但是disconnectneecting似乎不能正常工作。
一旦我关闭我的应用程序,我无法访问互联网。我得手动禁用TAP适配器,然后启用再次执行应用程序。
我检查了我的路线打印和是点击是在互联网领先,因此无法访问网络。
I am tring to connect a remote server via openvpn using C#. I am able to connect it successfully. but disconneecting seems to not work properly.Once I close my app, I am not able to access the internet. I got to manually disable the TAP Adapter and then enable to execute the app again.I checked my "route print" and yes Tap is coming ahead of internet and hence couldn't access net.
我连接使用:
openvpn --config client.ovpn --ca certificate.cer --auth-user-pass user.txt
I connect using :openvpn --config client.ovpn --ca certificate.cer --auth-user-pass user.txt
我的断开连接代码是:
public void DisconnectServer()
{
// Write the logs
if (sb != null)
IOUtility.WriteToFile(sb.ToString(), "ConnectionLogs.log");
processInfo = null;
if (process != null)
{
//process.Close();
if (!process.HasExited)
{
process.CancelOutputRead();
ProcessThreadCollection ptc = process.Threads;
Console.WriteLine("////// PROCESSED THREAD = " + ptc.Count);
for (int i = 0; i > ptc.Count; i++)
{
ProcessThread pt = ptc[i];
pt.Dispose();
ptc.Remove(pt);
Console.WriteLine("REmoed Thread @ " + i);
}
process.CloseMainWindow();
process.Kill();
}
}
sb = null;
connected = false;
}
在搜索这个问题的网上,我发现使用管理退出openvpn安全。但我不能做如何运行managemetn代码。虽然开始我添加:
openvpn --config ca.ovpn --ca cert.cer --management 127.0.0.1 12345
然后如何给SIGTERM信号关闭openvpn。
在新的cmd中,我尝试:openvpn --management-signal SIGTERM,但是不能正常工作。
On searching net for this issue, I found to use management to exit the openvpn safely. But I cannot make how to run the managemetn code. While start I added :openvpn --config ca.ovpn --ca cert.cer --management 127.0.0.1 12345Then how to give SIGTERM signal to close the openvpn.In new cmd, I tried : openvpn --management-signal SIGTERM but things doesn't work.
OpenVpn不会安装为服务我想不能使用--service属性。
OpenVpn will not be installed as a Service, so I guess can't use --service attribute.
任何人都可以指导我在断开连接时出现错误。如何处理managemetn信号代码。
这是从openvpn服务器断开连接的最佳方式。我也可以退出openvpn本身吗?
Can anyone guide me where am I going wrong in disconnecting. How to handle the managemetn-signal code.Which is the best way to disconnet from openvpn server. Can I also exit the openvpn itself ?
请帮我。在互联网上搜索了很多,并找到一些帮助,但没有成功。
Kindly help me. Have searched a lot on internet and found some help but no sucess yet. Stuck on this issue.
感谢
推荐答案
我找到了解决方案,这是我如何成功:
I found the solution and this is how I suceeded :
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName.StartsWith("openvpn"))
{
p.Kill();
Console.WriteLine("Killed Process");
break;
}
}
而不是使用它的线程和所有,代码帮助解决了这个问题。
Instead of working with its thread and all, the above code helped out to solve the problem.
我希望这也能帮助别人。
I hope this helps others too.
这篇关于解决从应用程序断开OpenVpn的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!