Net
Description
This is a collection of network related tools.
Tools
get ip(string) of interfaces
ips, _ := Net.GetIP("eth0")
fmt.Println(ips)
output:
[fe80::1111:2222:3333:4444 1.1.1.1]get the type of ip
ipv4 := "1.1.1.1"
ipv6 := "fe80::1111:2222:3333:4444"
fmt.Println(Net.WhichType(ipv4),", ",Net.Which(ipv6))
output:
4convert type string to number string
fmt.Println(Net.Type2Num("4"))
fmt.Println(Net.Type2Num("6"))
fmt.Println(Net.Type2Num("A"))
fmt.Println(Net.Type2Num("AAAA"))
fmt.Println(Net.Type2Num("5"))
fmt.Println(Net.Type2Num("AAA"))
output:
4
6
4
6
// empty string
//
convert number string type to string type
convert string type to uint8 type
ip Handler
Handle ip slice, apply handler to each ip element
Work as Filter
Built-in Handler: RemoveLoopback ReserveLoopbackOnly RemoveGlobalUnicast ReserveGlobalUnicastOnly
// it's not recommended to use this, just to use ip[no] instead, NewSelector(no uint64) if you want to select the second ip, you can use Net.NewSelector(1) // start from 0
handlers will be applied in order
最后更新于
这有帮助吗?