ip golang of network operation

net IP packet type defined as an array of bytes

type IP []byte

 

ParseIP (string) function to get the number of points divided IPV6 addresses IPV4 divided or wear, such as 127.0.0.1 or 0: 0: 0: 0: 0: 0: 0: 1

Method returns the string with a string IP

package main

import (
"fmt"
"net"
"os"
)

func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage %s ip-addr\n", os.Args[0])
os.Exit (-1)
}

name := os.Args[1]
addr := net.ParseIP(name)
if addr == nil {
fmt.Println("Invalid address")
} else {
fmt.Println("The address is ", addr.String())
}
}

Guess you like

Origin www.cnblogs.com/udont/p/12508048.html