S
S
s_pyanov2017-01-18 05:05:32
go
s_pyanov, 2017-01-18 05:05:32

How to change the MAC address of a network adapter in windows from a program written in GO?

Good day to all!
It was required to change the mac address of the network. Tell me how to implement it? through which package?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem @Jump, 2017-01-18
curated by the

There is no MAC address in the program, so there is nothing to change.
The network card has a MAC address and you can change it either in the driver of this card itself, or in the Windows registry.

S
s_pyanov, 2017-01-18
@s_pyanov

Artem , Everything seems clear from the question (the first "GO" tag specifically indicates this). Regarding the registry, it didn’t come to my mind right away, because. in the go language there is a "net" library that, through the HardwareAddr method, allows you to read the current value of the hardware address (where this method itself takes the information from is not at all clear to me). I suggested that perhaps there is a library that implements access to the value of the hardware address (through the wasps or through the driver or through something else (remembering the magic of HardwareAddr)). I could not find such a library, and asked the question here. While waiting for an answer, I thought of the registry ...
if it helps someone:
the package for working with the registry can be used "golang.org/x/sys/windows/registry"
But my problem is not solved yet! The decision to work with the registry is still a crutch, because. it is necessary to process the "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}\" branch, then parse the nth number of branches in it and parse the parameters ... this works, but this not at all elegant ((
so I want to interact with existing code ...

iface, _ := net.Interfaces()
  for _, inter := range iface {
    fmt.Println("iface=", inter.Name, " mac=", inter.HardwareAddr)
    if inter.Name == "Ethernet" {
      fmt.Println("работаем с Ethernet")
      fmt.Println("iface=", inter.Name, " mac=", inter.HardwareAddr) //текущие значения IP и MAC
    }
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question