1

I wrote a simple tcp server in go. I'm wondering if it is possible to get the MAC (Hardware address) from particular client ?

Example to better understanding me, can be below piece of code:

func main() {

    l, err := net.Listen("tcp4", "0.0.0.0:1234")
    if err != nil {
        fmt.Println("Error listening:", err.Error())
        os.Exit(1)
    }
    defer l.Close()
    fmt.Println("Listening....")
    for {
        conn, err := l.Accept()
        if err != nil {
            fmt.Println("Error accepting: ", err.Error())
            os.Exit(1)
        }

       // How do I get the Hardware Adres (MAC) from particular client from here?
    }
}
Rick Smith
  • 9,031
  • 15
  • 81
  • 85
Mbded
  • 1,754
  • 4
  • 23
  • 43
  • 5
    Also dupes: http://stackoverflow.com/questions/8046725/get-mac-address-of-remote-pc, http://stackoverflow.com/questions/3385/mac-addresses-in-javascript, and I'm sure several other versions in lots of languages. The answer is no (it doesn't matter the language). – Rob Napier Sep 29 '15 at 22:44
  • @RobNapier you should maybe first clarify why he needs the MAC before closing it blindly from dupes of other languages. – Stephan Dollberg Sep 30 '15 at 06:33
  • Easy. Probalby this is will not happend, because as I suspected socket `TCP is in diffrent layer network`. He have information about: port, IP source, IP destynation, Flags and etc, but doesn't have information about MAC. https://en.wikipedia.org/wiki/Transmission_Control_Protocol MAC is in Data Link Layer , But I not be sured to end it is possible in golang... BTW thank You for answer – Mbded Sep 30 '15 at 06:49
  • 3
    Just to make it clear for later readers, this answer has nothing to do with Go. There is no language, OS, or hardware combination that can solve this on a routed IP network (and not even on some "switched" networks). The originating MAC is not in the packet. It's not part of the protocol. That's why it's best to dupe these questions (2nd time this week I've seen it) and point to the established answers, even if they were originally framed in some other language. Hopefully that will help future questioners find their answer quickly. – Rob Napier Sep 30 '15 at 13:09
  • MAC addresses aren't included in the TCP/IP headers, so there's no way to know the MAC address (You *could* if you were on the same subnet, but doesn't look like that's what you're asking for). – rohitpaulk Oct 01 '15 at 13:36

0 Answers0