dongzhong5967 2017-11-17 16:41
浏览 117

如何发现网络设备类型?

On any given computer (OSX, WIn, Lin, etc) there are any number of connected network adapters... whether it's Wi-Fi, BlueTooth, Ethernet or other... And depending on the routing there may be multiple active devices.

In my NARROW use case I want to know what the current CONNECTED default adapter type (Wi-Fi etc...) although once that's known there are easily some others as well as some details.

Here is an example shell script that mostly works and converting it to Go is easy enough... it just seems to me there must be a native GO way.

  • 写回答

2条回答 默认 最新

  • dongyi2889 2017-11-17 17:26
    关注

    You can use Interfaces() from net package

    Sample:

    package main
    
    import (
        "fmt"
        "net"
    )
    
    func main() {
        l, err := net.Interfaces()
        if err != nil {
            panic(err)
    
        }
        for _, f := range l {
            if f.Flags&net.FlagUp > 0 {
                fmt.Printf("%s is up
    ", f.Name)
            }
        }
    }
    
    评论

报告相同问题?