package main

import (
"fmt"
"net"
"reflect" "github.com/thinkeridea/go-extend/exnet"
) func main() {
ip := "192.168.1.1" n, _ := exnet.IPString2Long(ip)
s, _ := exnet.Long2IPString(n) fmt.Println(n, s == ip) Ip1 := net.ParseIP(ip) // 会得到一个16字节的byte,主要为了兼容ipv6
n, _ = exnet.IP2Long(Ip1) Ip2, _ := exnet.Long2IP(n) fmt.Println(n, reflect.DeepEqual(Ip1[12:], Ip2))
}

Go -- IP to int ip字符串和十进制相互转化的更多相关文章

  1. C# 获取本机IP地址以及转换字符串

    /// <summary> /// IP地址转化 /// </summary> /// <param name="ipaddr">整型的IP地址 ...

  2. IP与十进制相互转化

    def ip2Long(ip: String): Long = { val fragments = ip.split("[.]")  var ipNum = 0L  for (i ...

  3. C语言实现字符串IP与整数型IP的相互转换

    #include <stdio.h> #include <stdlib.h> #include <string.h> #include <malloc.h&g ...

  4. php中ip转int 并存储在mysql数据库

    遇到一个问题,于是百度一下. 得到最佳答案 http://blog.163.com/metlive@126/blog/static/1026327120104232330131/     如何将四个字 ...

  5. [LeetCode] Validate IP Address 验证IP地址

    In this problem, your job to write a function to check whether a input string is a valid IPv4 addres ...

  6. [LeetCode] Restore IP Addresses 复原IP地址

    Given a string containing only digits, restore it by returning all possible valid IP address combina ...

  7. C#获取本机IP以及无线网ip

       1 private void GetIP()   2 { 3 string hostName = Dns.GetHostName();//本机名 4 //System.Net.IPAddress ...

  8. python3通过纯真IP数据库查询IP归属地信息

    在网上看到的别人写的python2的代码,修改成了python3. 把纯真IP数据库文件qqwry.dat放到czip.py同一目录下. #! /usr/bin/env python # -*- co ...

  9. uva 1590 - IP Networks(IP地址)

    习题4-5 IP网络(IP Networks, ACM/ICPC NEERC 2005, UVa1590) 可以用一个网络地址和一个子网掩码描述一个子网(即连续的IP地址范围).其中子网 掩码包含32 ...

随机推荐

  1. Java中异常关键字throw和throws使用方式的理解

    Java中应用程序在非正常的情况下停止运行主要包含两种方式: Error 和 Exception ,像我们熟知的 OutOfMemoryError 和 IndexOutOfBoundsExceptio ...

  2. c# 属性成员

  3. nginx编译安装和功能介绍

    nginx介绍 nginx: engine X,是由1994年毕业于俄罗斯国立莫斯科鲍曼科技大学的同学为俄罗斯rambler.ru公司开发的,开发工作最早从2002年开始,第一次公开发布时间是2004 ...

  4. (2) openstack--keystone

    yun1 OpenStack packages yum install python-openstackclient -y yum install openstack-selinux SQL data ...

  5. js中的forEach和map的区别

    我们先来看两者之间的相同之处 var arr = ['a','b','c','d']; arr.forEach(function(item,index,arr){ //item表示数组中的每一项,in ...

  6. java.lang.AbstractMethodError: org.powermock.api.mockito.internal.mockmaker.PowerMockMaker.isTypeMockable

    [转]https://stackoverflow.com/questions/53539930/java-lang-abstractmethoderror-org-powermock-api-mock ...

  7. python中json序列化时汉字变成编码的解决方式

    我们在使用json模块时,如果被序列化对象中不包含汉字,当然没有任何问题,但是有汉字会被编译成unicode码: import json dic = {","sex":& ...

  8. 斜率优化DP总结

    HDU3507 Print Article Zero has an old printer that doesn't work well sometimes. As it is antique, he ...

  9. Hive窗口函数案例详解

    语法: 分析函数 over(partition by 列名 order by 列名 rows between 开始位置 and 结束位置) 常用分析函数: 聚合类 avg().sum().max(). ...

  10. JavaScript 常用Object

    对象 - Map 功能:Map 对象保存键值对. 方法: new Map():新建一个 Map 对象 Map.prototype.has(key):返回布尔值.表示 Map 实例是否包含键对应的值. ...