golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
124.23k stars 17.7k forks source link

net: Interfaces() does not return all interfaces on Windows #37652

Open ChenYahui2019 opened 4 years ago

ChenYahui2019 commented 4 years ago

What version of Go are you using (go version)?

$ go version
go version go1.13.4 linux/amd64

Does this issue reproduce with the latest release?

Y

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/root/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/golang"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build467654165=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I am trying to use net.Interfaces() to get all interfaces on Windows, however, some interfaces can only display using Wireshark.

What did you expect to see?

If Wireshark was able to display an interface on Windows, net.Interfaces() can also do the same.

What did you see instead?

Some interfaces can be seen using Wireshark on Windows, which cannot been seen by net.Interfaces().

ChenYahui2019 commented 4 years ago

I found the list of net.Interfaces() is same with ipconfig or GetAdaptersAddresses/GetAdaptersInfo, Wireshark use another Windows API pcap.FindAllDevs/pcapFindalldevsPtr.

So, may net.Interfaces() chang the method of getting all interfaces here?

toothrot commented 4 years ago

/cc @mikioh @alexbrainman @bradfitz

alexbrainman commented 4 years ago

I found the list of net.Interfaces() is same with ipconfig or GetAdaptersAddresses/GetAdaptersInfo, Wireshark use another Windows API pcap.FindAllDevs/pcapFindalldevsPtr.

Sorry, but I don't have time even to investigate this. I don't think net.Interfaces is very useful on Windows.

Alex

bradfitz commented 4 years ago

What types of interfaces does Wireshark include that Go/ipconfig do not?

ChenYahui2019 commented 4 years ago

@bradfitz The NIC2 which is used for Hyper-v vswitch.

PS C:\Program Files> Get-NetAdapter

Name                      InterfaceDescription                    ifIndex Status       MacAddress             LinkSpeed
----                      --------------------                    ------- ------       ----------             ---------
NIC4                      Broadcom NetXtreme Gigabit Ethernet          19 Disconnected C8-1F-66-F8-24-A8          0 bps
NIC3                      Broadcom NetXtreme Gigabit Ethernet #2       18 Disconnected C8-1F-66-F8-24-A7          0 bps
vEthernet (vswitch123)    Hyper-V Virtual Ethernet Adapter             45 Up           C8-1F-66-F8-24-A6         1 Gbps
Npcap Loopback Adapter    Npcap Loopback Adapter                       65 Up           02-00-4C-4F-4F-50       1.2 Gbps
NIC2                      Broadcom NetXtreme Gigabit Ethernet #3       10 Up           C8-1F-66-F8-24-A6         1 Gbps
NIC1                      Broadcom NetXtreme Gigabit Ethernet #4        7 Up           C8-1F-66-F8-24-A5         1 Gbps

PS C:\Program Files> Get-VMSwitch vswitch123

Name       SwitchType NetAdapterInterfaceDescription
----       ---------- ------------------------------
vswitch123 External   Broadcom NetXtreme Gigabit Ethernet #3

PS C:\Program Files> ipconfig.exe

Windows IP 配置

以太网适配器 NIC4:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :

以太网适配器 NIC3:

   媒体状态  . . . . . . . . . . . . : 媒体已断开连接
   连接特定的 DNS 后缀 . . . . . . . :

以太网适配器 NIC1:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : xxxx::xxx:xxxxx:xxxx:xxxxxxxx
   IPv4 地址 . . . . . . . . . . . . : 172.16.1.134
   子网掩码  . . . . . . . . . . . . : 255.255.0.0
   默认网关. . . . . . . . . . . . . :

以太网适配器 Npcap Loopback Adapter:

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : xxxx::xxx:xxxxx:xxxx:xxxxxxxx
   自动配置 IPv4 地址  . . . . . . . : 169.254.70.224
   子网掩码  . . . . . . . . . . . . : 255.255.0.0
   默认网关. . . . . . . . . . . . . :

以太网适配器 vEthernet (vswitch123):

   连接特定的 DNS 后缀 . . . . . . . :
   本地链接 IPv6 地址. . . . . . . . : xxxx::xxx:xxxxx:xxxx:xxxxxxxx
   IPv4 地址 . . . . . . . . . . . . : x.x.x.x
   子网掩码  . . . . . . . . . . . . : 255.255.0.0
   默认网关. . . . . . . . . . . . . : x.x.x.x