基本信息
源码名称:C# DotRas 获取IP地址(本地和网络ip地址,限拨号网络)
源码大小:0.15M
文件格式:.rar
开发语言:C#
更新时间:2016-04-14
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍

using System;
using System.Windows.Forms;

namespace DotRas.Samples.GetActiveConnectionIPAddress
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void LoadConnectionsComboBox()
        {
            this.ConnectionsComboBox.Items.Add(new ComboBoxItem("Choose one...", null));

            foreach (RasConnection connection in RasConnection.GetActiveConnections())
            {
                this.ConnectionsComboBox.Items.Add(new ComboBoxItem(connection.EntryName, connection.EntryId));
            }

            this.ConnectionsComboBox.SelectedIndex = 0;
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.LoadConnectionsComboBox();
        }

        private void GetAddressButton_Click(object sender, EventArgs e)
        {
            foreach (RasConnection connection in RasConnection.GetActiveConnections())
            {
                if (connection.EntryId == (Guid)((ComboBoxItem)this.ConnectionsComboBox.SelectedItem).Value)
                {
                    RasIPInfo ipAddresses = (RasIPInfo)connection.GetProjectionInfo(RasProjectionType.IP);
                    if (ipAddresses != null)
                    {
                        this.ClientAddressTextBox.Text = ipAddresses.IPAddress.ToString();
                        this.ServerAddressTextBox.Text = ipAddresses.ServerIPAddress.ToString();
                    }
                }
            }
        }

        private void ConnectionsComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GetAddressButton.Enabled = this.ConnectionsComboBox.SelectedIndex > 0;
        }
    }
}