update
continuous-integration/drone/push Build is passing Details

master
李光春 2 years ago
parent 8b5684e301
commit e54387822f

@ -22,4 +22,23 @@ go get -v -u go.dtapp.net/goip
import (
"go.dtapp.net/goip"
)
```
```go
package main
import (
"go.dtapp.net/goip"
"testing"
)
func TestGoIp(t *testing.T) {
// 获取Mac地址
t.Log(goip.GetMacAddr())
// 内网ip
t.Log(goip.GetInsideIp())
// 外网ip
t.Log(goip.GetOutsideIp())
}
```

17
ip.go

@ -71,3 +71,20 @@ func GetOutsideIp() (ip string) {
ip = respGetOutsideIp.Data.Ip
return respGetOutsideIp.Data.Ip
}
// GetMacAddr 获取Mac地址
func GetMacAddr() (arrays []string) {
netInterfaces, err := net.Interfaces()
if err != nil {
return arrays
}
for _, netInterface := range netInterfaces {
addr := netInterface.HardwareAddr.String()
if len(addr) == 0 {
continue
}
arrays = append(arrays, addr)
}
return arrays
}

@ -13,3 +13,7 @@ func TestGetInsideIp(t *testing.T) {
func TestIps(t *testing.T) {
t.Log(Ips())
}
func TestGetMacAddr(t *testing.T) {
t.Log(GetMacAddr())
}

Loading…
Cancel
Save