mirror of https://github.com/bjdgyc/anylink.git
优化ip分配
This commit is contained in:
parent
7b83154245
commit
201a62144e
|
@ -30,6 +30,7 @@ require (
|
|||
go.uber.org/atomic v1.10.0
|
||||
golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f
|
||||
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4
|
||||
golang.org/x/text v0.3.7
|
||||
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
|
||||
layeh.com/radius v0.0.0-20210819152912-ad72663a72ab
|
||||
xorm.io/xorm v1.2.2
|
||||
|
@ -66,7 +67,6 @@ require (
|
|||
github.com/tklauser/numcpus v0.2.3 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
|
|
|
@ -92,7 +92,12 @@ func LinkAuth(w http.ResponseWriter, r *http.Request) {
|
|||
// 获取客户端mac地址
|
||||
macHw, err := net.ParseMAC(sess.MacAddr)
|
||||
if err != nil {
|
||||
sum := md5.Sum([]byte(sess.UniqueIdGlobal))
|
||||
var sum [16]byte
|
||||
if sess.UniqueIdGlobal != "" {
|
||||
sum = md5.Sum([]byte(sess.UniqueIdGlobal))
|
||||
} else {
|
||||
sum = md5.Sum([]byte(sess.Token))
|
||||
}
|
||||
macHw = sum[0:5] // 5个byte
|
||||
macHw = append([]byte{0x02}, macHw...)
|
||||
sess.MacAddr = macHw.String()
|
||||
|
|
|
@ -92,9 +92,9 @@ func AcquireIp(username, macAddr string) net.IP {
|
|||
ipStr := mi.IpAddr
|
||||
ip := net.ParseIP(ipStr)
|
||||
// 跳过活跃连接
|
||||
// _, ok := ipActive[ipStr]
|
||||
_, ok := ipActive[ipStr]
|
||||
// 检测原有ip是否在新的ip池内
|
||||
if IpPool.Ipv4IPNet.Contains(ip) &&
|
||||
if IpPool.Ipv4IPNet.Contains(ip) && !ok &&
|
||||
utils.Ip2long(ip) >= IpPool.IpLongMin &&
|
||||
utils.Ip2long(ip) <= IpPool.IpLongMax {
|
||||
mi.Username = username
|
||||
|
|
Loading…
Reference in New Issue