Skip to content

Instantly share code, notes, and snippets.

@smallnest
Forked from ammario/ipint.go
Created September 26, 2021 04:51
Show Gist options
  • Save smallnest/512857d0d66d8b1a1dd1116e086107c3 to your computer and use it in GitHub Desktop.
Save smallnest/512857d0d66d8b1a1dd1116e086107c3 to your computer and use it in GitHub Desktop.

Revisions

  1. @ammario ammario created this gist Jun 5, 2016.
    12 changes: 12 additions & 0 deletions ipint.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    func ip2int(ip net.IP) uint32 {
    if len(ip) == 16 {
    return binary.BigEndian.Uint32(ip[12:16])
    }
    return binary.BigEndian.Uint32(ip)
    }

    func int2ip(nn uint32) net.IP {
    ip := make(net.IP, 4)
    binary.BigEndian.PutUint32(ip, nn)
    return ip
    }