Search code examples
c#vpnnetwork-interface

Get VPN Ip address


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?


Solution

  • 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();