net

command
v0.0.0-...-280f8e7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 19, 2024 License: CC0-1.0 Imports: 2 Imported by: 0

README

net Listando Interfaces e IPs

Um exemplo simples listando as interfaces de rede.

package main

import (
	"fmt"
	"net"
)

func main() {
	ifaces, _ := net.Interfaces()
	for _, i := range ifaces {

		fmt.Printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\n")
		fmt.Printf("%v - %v\n", i.Name, i.HardwareAddr)
		addrs, err := i.Addrs()
		if err != nil {
			panic(err.Error())
		}

		for _, a := range addrs {
			if ipnet, ok := a.(*net.IPNet); ok {
				if ipnet.IP.To4() != nil {
					fmt.Printf("ip: %v\n", ipnet.IP.String())
				} else {
					fmt.Printf("ipv6: %v\n", ipnet.IP.String())

				}
			}
		}
	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL