Browse Source

添加对网卡的支持

lxg 3 years ago
parent
commit
b58e0c9ea1
1 changed files with 16 additions and 0 deletions
  1. 16 0
      helper/machineid/id_linux.go

+ 16 - 0
helper/machineid/id_linux.go

@@ -3,6 +3,12 @@
 
 package machineid
 
+import (
+	"crypto/md5"
+	"encoding/hex"
+	"net"
+)
+
 func getMachineID() (s string, err error) {
 	paths := []string{
 		"/var/lib/dbus/machine-id",
@@ -18,5 +24,15 @@ func getMachineID() (s string, err error) {
 			return
 		}
 	}
+	//计算网卡信息
+	h := md5.New()
+	if is, err := net.Interfaces(); err == nil {
+		for _, i := range is {
+			if i.HardwareAddr != nil {
+				h.Write(i.HardwareAddr)
+			}
+		}
+	}
+	s = hex.EncodeToString(h.Sum(nil))
 	return
 }