함수 int2ip()

1 개요[ | ]

함수 int2ip()
함수 long2ip()

2 Go[ | ]

package main

import (
	"encoding/binary"
	"fmt"
	"net"
)

func int2ip(ipInt int) string {
	if ipInt < 0 || ipInt > 4294967295 {
		return ""
	}
	ip := make(net.IP, 4)
	binary.BigEndian.PutUint32(ip, uint32(ipInt))
	return ip.String()
}
func main() {
	fmt.Println(int2ip(0))          // 0.0.0.0
	fmt.Println(int2ip(1))          // 0.0.0.1
	fmt.Println(int2ip(256))        // 0.0.1.0
	fmt.Println(int2ip(2270164560)) // 135.79.246.80
	fmt.Println(int2ip(4294967295)) // 255.255.255.255

	fmt.Println(int2ip(-1))         // ""
	fmt.Println(int2ip(4294967296)) // ""
}

3 PHP[ | ]

var_dump( long2ip(0) );   # string(7) "0.0.0.0"
var_dump( long2ip(1) );   # string(7) "0.0.0.1"
var_dump( long2ip(256) ); # string(7) "0.0.1.0"
var_dump( long2ip(4294967295) ); # string(15) "255.255.255.255"
var_dump( long2ip(-1) ); # string(15) "255.255.255.255"
var_dump( long2ip(2270164560) ); # string(13) "135.79.246.80"
var_dump( long2ip(9999999999999) ); # string(14) "78.114.159.255"

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}