Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 543
DaveUK Avatar asked Sep 13 '25 21:09

DaveUK


1 Answers

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

like image 59
Jurion Avatar answered Sep 15 '25 14:09

Jurion