2021-12-03 08:46:18 +00:00
|
|
|
package script
|
|
|
|
|
|
|
|
|
|
import (
|
2021-12-04 04:06:45 +00:00
|
|
|
"bytes"
|
|
|
|
|
"math/rand"
|
2021-12-03 08:46:18 +00:00
|
|
|
"net"
|
2021-12-04 04:06:45 +00:00
|
|
|
"time"
|
2021-12-03 08:46:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GetIpAddress() string {
|
|
|
|
|
addrs, _ := net.InterfaceAddrs()
|
|
|
|
|
for _, value := range addrs {
|
|
|
|
|
if ipnet, ok := value.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
|
|
|
|
if ipnet.IP.To4() != nil {
|
|
|
|
|
return ipnet.IP.String()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|
2021-12-04 04:06:45 +00:00
|
|
|
|
|
|
|
|
const char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
|
|
|
|
|
|
|
|
|
func RandChar(size int) string {
|
|
|
|
|
rand.NewSource(time.Now().UnixNano()) // 产生随机种子
|
|
|
|
|
var s bytes.Buffer
|
|
|
|
|
for i := 0; i < size; i++ {
|
|
|
|
|
s.WriteByte(char[rand.Int63()%int64(len(char))])
|
|
|
|
|
}
|
|
|
|
|
return s.String()
|
|
|
|
|
}
|