Extract Gateway ID in C#.net

How to Extract Gateway ID in C#.net

using System;

using System.Collections.Generic;

using System.Text;

using System.Net.NetworkInformation;

 

namespace Decorator_Console

{

    public class ClsGatewayID

    {

        private static string _GatewayID = string.Empty;

 

        public static string GatewayID

        {

            get

            {

                return mGetGatewayID();

            }

        }

 

        private static string mGetGatewayID()

        {

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface adapter in adapters)

            {

                IPInterfaceProperties adapterProperties = adapter.GetIPProperties();

                GatewayIPAddressInformationCollection addresses = adapterProperties.GatewayAddresses;

                    if (addresses.Count > 0)

                    {

                        foreach (GatewayIPAddressInformation address in addresses)

                        {

                       

                          if(string.IsNullOrEmpty(_GatewayID))

                              _GatewayID += address.Address.ToString();

                          else

                              _GatewayID += address.Address.ToString() + "\r\n";

 

                        }

                    }

             }

 

            return _GatewayID;

        }

    }

}

By Kalit Sikka   Popularity  (1656 Views)