Skip to content

Latest commit

 

History

History
30 lines (19 loc) · 619 Bytes

ParseIP.md

File metadata and controls

30 lines (19 loc) · 619 Bytes

func ParseIP(s string) IP

参数列表:

  • s ip地址字符串,可以是IPv4或IPv6格式( ("74.125.19.99") or ("2001:4860:0:2001::68") )

返回列表:

  • IP IP结构

解析IP地址,返回IP结构

代码实例:

package main

import "fmt"
import "net"

func main() {
	ip := net.ParseIP("74.125.19.99")
	fmt.Printf("%#v",ip)
	ip = net.ParseIP("2001:4860:0:2001::68")
	fmt.Printf("%#v",ip)

}

函数输出:

net.IP{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xff, 0xff, 0x4a, 0x7d, 0x13, 0x63}
net.IP{0x20, 0x1, 0x48, 0x60, 0x0, 0x0, 0x20, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68}