Search code examples
c#windows-runtimeipv4uint

C# - WinRT - Convert IPv4 address from uint to string?


I have a IPv4 address provided as a uint and I would like to convert it to string (for the purpose of logging).

I would normally achieve this in C# using the System.Net.IPAddress constructor...but it seems that System.Net.IPAddress is not available in C# for WinRT/Windows Store. Does anyone have an equivalent way to do this conversion?

Thank you.


Solution

  • A little "dirty", but seems to work

            uint ip = 0xFFDF5F4F;
            var bytes = BitConverter.GetBytes(ip);
            string res = string.Join(".", bytes.Reverse());
    

    Output is 255.223.95.79 for this case