Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determining physical ethernet device #957

Open
purpleidea opened this issue Mar 8, 2024 · 0 comments
Open

Determining physical ethernet device #957

purpleidea opened this issue Mar 8, 2024 · 0 comments

Comments

@purpleidea
Copy link

I'm running this code:

package main

import "fmt"
import "github.com/vishvananda/netlink"

func main() {
	links, err := netlink.LinkList()
	if err != nil {
		panic(err)
	}
	fmt.Printf("links: %+v\n", links)
	for i, link := range links {
		fmt.Printf("link(%d): %+v\n", i, link.Type())
		attrs := link.Attrs()
		fmt.Printf("link(%d): Name: %+v\n", i, attrs.Name)
		fmt.Printf("link(%d): Name: %+v\n", i, attrs.Name)
	}
}

I've got loopback, one bridge, one wifi device, and one physical ethernet port. I've printed out the output from the wifi and ethernet device. I've also removed most identical fields and censored the mac addresses:

&{Index:2 MTU:1500 TxQLen:1000 Name:enp0s31f6 HardwareAddr:xx:xx:xx:xx:xx:xx Flags:up|broadcast|multicast RawFlags:4099  Alias: Statistics:0xc0000da180  Xdp:0xc0000c2090 EncapType:ether  OperState:down }

&{Index:3 MTU:1500 TxQLen:1000 Name:wlp0s20f3 HardwareAddr:yy:yy:yy:yy:yy:yy Flags:up|broadcast|multicast RawFlags:69699 Alias: Statistics:0xc0000da300  Xdp:0xc0000c20a8 EncapType:ether OperState:up }

Apart from parsing the name, I don't know how to tell programatically which is the physical ethernet device and which is wifi. Is there a way?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant