本文介绍了在.NET Core中将IP地址转换为UInt32/UInt64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个v4 IP地址.我需要将其转换为UInt32.在常规.NET中,我使用的是:

I have a v4 IP Address. I need to convert it to UInt32.In regular .NET, I was using:

string address = "192.168.1.1";
long intAddress = (long)(uint)IPAddress.NetworkToHostOrder((int)IPAddress.Parse(address).Address);

但是IPAddress.Address在.NET Core中不可用.什么是替代品?

But IPAddress.Address is not available in .NET Core.What's the replacement?

推荐答案

var address = IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(IPAddress.Parse(ipAddress).GetAddressBytes(), 0));

这篇关于在.NET Core中将IP地址转换为UInt32/UInt64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 08:59