How to Get Client IP Address Through X++ in Ax

Description: System.Net Provides a container class for Internet host address information.Syste.Net.IPAddress [] Gets or sets a list of IP addresses that are associated with a host. IPHostEntry.HostName Gets or sets the DNS name of the host. Create Job and Run below Code to Get Client IP Address.

static void FetchIpAddress (Args _args)
{
    System.StringhostName = System.Net.Dns::GetHostName();
    System.Net.IPHostEntryhostEntry = System.Net.Dns::GetHostEntry(hostName);
    System.Net.IPAddress[]              addresses = hostEntry.get_AddressList();
    System.Net.IPAddress                address;
    System.Net.Sockets.AddressFamilyaddressFamily;
    System.Collections.IEnumerator      enumerator = addresses.GetEnumerator();
    while (enumerator.MoveNext())
    {
        address = enumerator.get_Current();
        addressFamily = address.get_AddressFamily();
        if (addressFamily == System.Net.Sockets.AddressFamily::InterNetwork)
        {
            info(address.ToString());
        }
    }
}

Related Posts

Previous
Next Post »

Thanks for comments.....