How to convert an IPv4 address into a integer in C#?
仅仅针对于IPv4的处理方法
从string转换为int
以及从int转换为string
// IPv4
int intAddress = BitConverter.ToInt32(IPAddress.Parse(address).GetAddressBytes(), 0);
string ipAddress = new IPAddress(BitConverter.GetBytes(intAddress)).ToString();
EDIT: As noted in other answers, when running this snippet on a little endian machine, it'll give out the bytes in the reverse order as defined by the standard. However, the question asks for a mapping between an integer and an IP address, not converting to the standard integer format. To do so, you have to consider the endian-ness of the machine you're running on.
How to convert an IPv4 address into a integer in C#?的更多相关文章
- Windows7 Autoconfiguration IPv4 Address 导致无法上网
Windows7 Autoconfiguration IPv4 Address 导致无法上 (2010-03-30 16:44:57) 转载▼ 标签: 杂谈 分类: 电脑软件问题 Windows7 A ...
- scala get ipv4 address
scala 用 isInstanceOf 会报错(instanceof 这个函数就没有),java 下使用 instanceof 来判断是否是 Inet4Address test("get ...
- 【解决】could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
在同一套环境中跑了很多个项目都是用 docker-compose的方式启动的,导致创建的自定义网络过多出现下面的报错 Error response from daemon: could not fin ...
- docker could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network
原因: 无法进行网络分配了 解决方法: // 所有的网络 docker network ls // 删除不用的,腾出多余的 docker network rm <networkname> ...
- IP地址转换32为长整型
Programming Question: Convert an IPv4 address in the format of null-terminated C string into a 32-bi ...
- netsh端口转发
使用多个虚拟机,将开发环境和工作沟通环境分开(即时通,办公系统都只能在windows下使用…),将开发环境的服务提供给外部访问时,需要在主机上通过代理配置数据转发. VirtualBox提供了端口 ...
- .bat文件设置IP、DNS
这几天遇到个烦心事,每次开机之后都要去手动去设置一下IP地址,一大串的数字还是有点麻烦,于是就想写个批处理文件设置IP 注意:在DOS下设置IP时需要管理员权限运行 1.查看机子设置IP需要用到的名字 ...
- windows下的端口转发命令netsh
使用下面的命令查看语法 netsh interface portproxy add v4tov4 /? add v4tov4 [listenport=]<integer>|<serv ...
- 【Windows】netsh动态配置端口转发
文章转载自傲风 使用多个虚拟机,将开发环境和工作沟通环境分开(即时通,办公系统都只能在windows下使用-),将开发环境的服务提供给外部访问时,需要在主机上通过代理配置数据转发. VirtualBo ...
随机推荐
- SQL Server delete、truncate、drop
在T-SQL中这三个命令符,相信很多朋友都不会陌生的,我自己在工作也会常常使用到它们,虽然我们清除的知道用这三个命令符可以达到怎样的预期效果. 但是却很少深入的去了解它们,知道它们有什么区别,又各有什 ...
- Unity 3D 文件导入出错误解决方法以及unity圣典离线版下载地址
1.安装unity 时我选择了free版的,打开已有项目时出现如下错误提示. 解决方法:先把要导入的文件先拷贝到unity3d安装目录下对应的文件夹内,之后再返回unity3d软件,右键选择“导入”. ...
- 谨以此错误警醒自己---java.lang.ClassNotFoundException:
今天在做一个小型的实例,用了面向接口编程,采用了工厂来获取数据源和实例,在从配置文件读取实例时,报了个错误如下图: 于是一个一个的类去找错误,最后也没找到,以为工厂代码出错了,看了好几次也没看出来错误 ...
- Android测试分析二
什么是android测试,分为黑盒测试和白盒测试. 黑盒就是测试人员看不到代码的,针对需求而进行的一系列测试动作,看代码所展现出来的效果是否和需求一样,或者有什么意外的情况没有处理等,一般开发交给测试 ...
- fastjson的坑 com.alibaba.fastjson.JSONObject cannot be cast to xxx
解析json对象时,使用了new TypeReference()对象 fastjson会对解析的对象类型进行缓存 new TypeReference<ResultData>(){} ...
- Android清空画布
public void clear() { Paint paint = new Paint(); paint.setXfermode(new PorterDuffXfermode(Mode.CLEAR ...
- 管理员把我的admin权限去掉了,那么如何获得jdk zip安装呢?这篇可以帮你。
JDK is not available as a portable zip unfortunately. However, you can: Create working JDK directory ...
- Libnids---编写网络应用程序的利器
一.前言 Libnids是一个用于网络入侵检测开发的专业编程接口,它使用Libpcap进行数据包的捕获.同时,Libnids提供了TCP/IP数据流重组功能,因此省去了应用层自己考虑数据分片.重传等情 ...
- wpf采用Xps实现文档显示、套打功能(原创)
近期的一个项目需对数据进行套打,用户要求现场不允许安装office.页面预览显示必须要与文档完全一致,xps文档来对数据进行处理.Wpf的DocumentView 控件可以直接将数据进行显示,xps也 ...
- onmouseleave与onmouseout区别
1.onmouseleave.onmouseenter,鼠标进入到指定元素区域内触发事件,不支持冒泡,不包含子元素的区域. 2.onmouseout.onmouseover.鼠标进入指定元素触发事件, ...