How can i get the ip from a PPP or PPPT vpn connection?
I know the name of the VPN connection, so how can i filter
var nics = NetworkInterface.GetAllNetworkInterfaces();
to only get the vpn interface with the name "VPNConnection", and get the given ip address?
Perhaps:
using System.Linq;
var vpn = NetworkInterface.GetAllNetworkInterfaces()
.First(x => x.Name == "VPNConnection");
EDIT: Whoops I didn't finish:
var ip = vpn.GetIPProperties().UnicastAddresses.First(x => x.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).Address.ToString();
I've made an application for this case. Using the batch file with following command, I made a process that executes the .bat file and stores the ip in variable ip
//make a batch file and write this in it
File.WriteAllText(FolderPath + "\\getip.bat", "@echo off \r\n FOR /F \"tokens=1-6 delims=:. \" %%a in ('netsh int ip show address \"SanadConnectVPN\" ^|find \"IP Address\"') do set IP=%%c.%%d.%%e.%%f \r\n echo %IP%");
var newProcess = new Process
{
StartInfo =
{
FileName = FolderPath + "\\getip.bat",
WindowStyle = ProcessWindowStyle.Normal
}
};
newProcess.StartInfo.RedirectStandardOutput = true;
newProcess.StartInfo.UseShellExecute = false;
newProcess.Start();
string ip = newProcess.StandardOutput.ReadToEnd();
newProcess.WaitForExit();
MessageBox.Show(ip);
return ip
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.