Commit 629a4038 authored by szh's avatar szh

update

parent d81a8008
......@@ -26,7 +26,7 @@ func Broadcast() {
panic("no serial no")
}
}
ip, err := GetRightIp()
ip, err := GetRightIP()
if err != nil {
panic(err)
}
......@@ -49,7 +49,7 @@ func Broadcast() {
}
for {
//ip 会变化
ip, err = GetRightIp()
ip, err = GetRightIP()
if err != nil {
panic(err)
}
......@@ -86,18 +86,18 @@ func Broadcast() {
}
func GetRightIp() (ipv4 *net.IPNet, err error) {
func GetRightIP() (ipv4 *net.IPNet, err error) {
//ip 会变化
ip, err := util.GetLocalIpByName("wlan0")
ip, err := util.GetLocalIPByName("wlan0")
if err != nil || ip == nil {
//tlog.Error("broadcast","wlan0", err)
ip, err = util.GetLocalIpByName("eth0")
ip, err = util.GetLocalIPByName("eth0")
if err != nil {
//tlog.Error("broadcast","eth0", err)
ip, err = util.GetLocalIpByName("wlp3s0")
ip, err = util.GetLocalIPByName("wlp3s0")
if err != nil || ip == nil {
//tlog.Error("broadcast","wlp3s0", err)
ip, err = util.GetLocalIpByName("enp2s0")
ip, err = util.GetLocalIPByName("enp2s0")
if err != nil {
//tlog.Error("broadcast", "enp2s0",err)
panic(err)
......@@ -115,7 +115,7 @@ func GetRightIps() (ipv4s []*net.IPNet, err error) {
return nil, err
}
for _, i := range interfaces {
ip, err := util.GetLocalIpByName(i.Name)
ip, err := util.GetLocalIPByName(i.Name)
if err != nil {
return nil, err
}
......
......@@ -637,6 +637,7 @@ func uploadInfo() error {
tlog.Error("uploadInfo", "NewRequest do", err)
return err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
tlog.Error("uploadInfo", "read", err)
......
......@@ -21,7 +21,7 @@ func GetLocalIP() (ipv4 *net.IPNet, err error) {
addrs []net.Addr
addr net.Addr
ipNet *net.IPNet // IP地址
isIpNet bool
isIPNet bool
)
// 获取所有网卡
......@@ -31,7 +31,7 @@ func GetLocalIP() (ipv4 *net.IPNet, err error) {
// 取第一个非lo的网卡IP
for _, addr = range addrs {
// 这个网络地址是IP地址: ipv4, ipv6
if ipNet, isIpNet = addr.(*net.IPNet); isIpNet && !ipNet.IP.IsLoopback() {
if ipNet, isIPNet = addr.(*net.IPNet); isIPNet && !ipNet.IP.IsLoopback() {
// 跳过IPV6
if ipNet.IP.To4() != nil {
ipv4 = ipNet // 192.168.1.1
......@@ -44,7 +44,7 @@ func GetLocalIP() (ipv4 *net.IPNet, err error) {
return
}
func GetLocalIpByName(name string) (ipv4 *net.IPNet, err error) {
func GetLocalIPByName(name string) (ipv4 *net.IPNet, err error) {
if name == "" {
return nil, errors.New("name not empty")
}
......@@ -56,13 +56,13 @@ func GetLocalIpByName(name string) (ipv4 *net.IPNet, err error) {
var (
addrs []net.Addr
ipNet *net.IPNet // IP地址
isIpNet bool
isIPNet bool
)
if addrs, err = inter.Addrs(); err != nil {
return nil, err
}
for _, addr := range addrs {
if ipNet, isIpNet = addr.(*net.IPNet); isIpNet && !ipNet.IP.IsLoopback() {
if ipNet, isIPNet = addr.(*net.IPNet); isIPNet && !ipNet.IP.IsLoopback() {
// 跳过IPV6
if ipNet.IP.To4() != nil {
ipv4 = ipNet // 192.168.1.1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment