How do you parse an IP address string to a uint value in C#?

后端 未结 9 735
庸人自扰
庸人自扰 2020-12-30 13:44

I\'m writing C# code that uses the windows IP Helper API. One of the functions I\'m trying to call is \"GetBestInterface\" that takes a \'uint\' representation of an IP. Wha

9条回答
  •  自闭症患者
    2020-12-30 14:06

    System.Net.IPAddress ipAddress = System.Net.IPAddress.Parse("192.168.1.1");
    
    byte[] bytes = ipAddress.GetAddressBytes();
    for (int i = 0; i < bytes.Length ; i++)
           Console.WriteLine(bytes[i]);
    

    Output will be 192 168 1 1

提交回复
热议问题