Monday, 7 December 2015

How To Get System IP Address through X++ Code


static void SystemIpAddress(Args _args)
{
     System.String              hostName    =   System.Net.Dns::GetHostName();
     System.Net.IPHostEntry     hostEntry   =   System.Net.Dns::GetHostEntry(hostName);
     System.Net.IPAddress[]     address     =   hostEntry.get_AddressList();
     System.Net.IPAddress       adress ;
     System.Net.Sockets.AddressFamily   adressFamily;
     System.Collections.IEnumerator     enumerator  =   address.GetEnumerator();

    while(enumerator.MoveNext())
    {
        adress  =   enumerator.get_Current();
        adressFamily = adress.get_AddressFamily();
        if(adressFamily == System.Net.Sockets.AddressFamily::InterNetwork)
        {
            info(adress.ToString());
        }
    }
}

No comments:

Post a Comment