Commit 629a4038 authored by szh's avatar szh

update

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