C# 获取网卡IP地址

NetworkInterface[] NetworkInterfaces = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface NetworkIntf in NetworkInterfaces)
{
    IPInterfaceProperties IPInterfaceProperties = NetworkIntf.GetIPProperties();
    UnicastIPAddressInformationCollection UnicastIPAddressInformationCollection = IPInterfaceProperties.UnicastAddresses;
    foreach (UnicastIPAddressInformation UnicastIPAddressInformation in UnicastIPAddressInformationCollection)
    {
        if (UnicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork)
        {
            Console.WriteLine(UnicastIPAddressInformation.Address);
        }
    }
}
posted @ 2008-04-07 15:10  Max Woods  阅读(1944)  评论(1编辑  收藏  举报