github.com/zooyer/miskit@v1.0.71/device/interface_linux.go (about)

     1  /**
     2   * @Author: zzy
     3   * @Email: zhangzhongyuan@didiglobal.com
     4   * @Description:
     5   * @File: interface_other.go
     6   * @Package: device
     7   * @Version: 1.0.0
     8   * @Date: 2022/10/5 15:07
     9   */
    10  
    11  package device
    12  
    13  import (
    14  	"net"
    15  	"os"
    16  	"strings"
    17  )
    18  
    19  func isPhysicalEthernet(index int) (is bool, err error) {
    20  	inf, err := net.InterfaceByIndex(index)
    21  	if err != nil {
    22  		return
    23  	}
    24  
    25  	// 读取网卡软连
    26  	link, err := os.Readlink("/sys/class/net/" + inf.Name)
    27  	if err != nil {
    28  		return
    29  	}
    30  
    31  	// 只可以使用pci网卡(电视盒子不支持)
    32  	if !strings.Contains(link, "/devices/pci") {
    33  		//return
    34  	}
    35  
    36  	// 不包含USB网卡
    37  	if strings.Contains(link, "usb") {
    38  		return
    39  	}
    40  
    41  	// 过滤掉虚拟网卡
    42  	if !strings.Contains(link, "/devices/virtual/net/") {
    43  		return true, nil
    44  	}
    45  
    46  	return
    47  }