|
Péter Szilágyi |
at Dec 15, 2013 at 9:51 am
|
⇧ |
| |
Hi,
This should do it:
package main
import (
"fmt"
"net"
)
func main() {
interfaces, _ := net.Interfaces()
for _, inter := range interfaces {
fmt.Println(inter.Name, inter.HardwareAddr)
if addrs, err := inter.Addrs(); err == nil {
for _, addr := range addrs {
fmt.Println(inter.Name, "->", addr)
}
}
}
}
Output:
lo
lo -> 127.0.0.1/8
lo -> ::1/128
eth0 00:1e:ec:8b:f2:63
wlan0 00:16:ea:b5:e8:e0
wlan0 -> 192.168.0.196/24
wlan0 -> fe80::216:eaff:feb5:e8e0/64
Cheers,
Peter
On Sun, Dec 15, 2013 at 11:30 AM, Curtis Paul wrote:Any ideas on how to list all of the local IP Address and Hardware
Addresses?
I understand the following, it provides Hardware Address...but the
Interface struct does not provide IP Address.
interfaces, _ := net.Interfaces()
for _, inter := range interfaces {
fmt.Println(inter.Name, inter.HardwareAddr)
}
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out. --
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.