解决方案 »

  1.   

    VPN连好后,相当于本机多了一块虚拟网卡,所以根据适配器的名字找到网卡,获取它的ip即可。
      

  2.   

    VPN分配的本来就是一个内网(VPN自己网段内)的地址。你需要知道什么IP,外网IP?外网IP跟VPN本身没什么关系,就是平常获取外网IP的方法,比如请求IP138.COM,然后解析出IP地址。
      

  3.   

    VPN链接后会分配的一个内网IP怎么获取到呢,但是获取只能获取本地网卡的IP,不需要外网的IP
      

  4.   

    参考: How do I determine the local host’s IPv4 addresses?
    传入你的VPN连接的名字,就可以获取它的IPV4地址using System;
    using System.Net;
    using System.Net.NetworkInformation;
    using System.Net.Sockets;
    using System.Text;namespace GetVPNIP
    {
    class Program
    {
    public static void Main(string[] args)
    {
    DisplayIPAddresses("你的VPN连接的名字");
    Console.Write("Press any key to continue . . . ");
    Console.ReadKey(true);
    }

    /// <summary>
    /// This utility function displays all the IP (v4, not v6) addresses of the local computer.
    /// </summary>
    public static void DisplayIPAddresses(string name)
    {
    StringBuilder sb = new StringBuilder(); // Get a list of all network interfaces (usually one per network card, dialup, and VPN connection)
    NetworkInterface[] networkInterfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface network in networkInterfaces)
    {
    if (network.Name == name) {

    // Read the IP configuration for each network
    IPInterfaceProperties properties = network.GetIPProperties(); // Each network interface may have multiple IP addresses
    foreach (IPAddressInformation address in properties.UnicastAddresses)
    {
    // We're only interested in IPv4 addresses for now
    if (address.Address.AddressFamily != AddressFamily.InterNetwork)
    continue; // Ignore loopback addresses (e.g., 127.0.0.1)
    if (IPAddress.IsLoopback(address.Address))
    continue; sb.AppendLine(address.Address.ToString() + " (" + network.Name + ")");
    sb.AppendLine()
    }
    break;
    }
    } Console.WriteLine(sb.ToString());
    }
    }
    }
      

  5.   

      foreach (RasConnection connection in RasConnection.GetActiveConnections())
               {
                   if (connection.EntryName == "KULENG-VPN-HK")
                   {///判断VPN名称是否相同
                       RasIPInfo ipAddresses = (RasIPInfo)connection.GetProjectionInfo(RasProjectionType.IP);                   if (ipAddresses != null)
                       {
                           newaddressip = ipAddresses.IPAddress.ToString();
                        
                          // string s3 = ipAddresses.ServerIPAddress.ToString();
                       }
                   }
               }我这里做了一个更简单的获取VPN分配IP的。大家的也可以学习,楼上的那种方法也是可以的
      

  6.   

    System.Net.NetworkInformation.NetworkInterface[] networkInterfaces = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
    foreach (var item in networkInterfaces)
    {
        if (item.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Ppp)
        {    }
    }
    六楼的代码改一下就可以了