Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The method used by GetIP to obtain effective intranet IP

Shulou Source: shulou.com Published: 2022-06-02 09:27:39 10月01日 Update

This article mainly explains "the method that GetIP uses to obtain effective intranet IP", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the method that GetIP uses to obtain effective intranet IP".

/ / GetIP is used to obtain valid private network IPfunc GetIP () ([] string, error) {netInterfaces, err: = net.Interfaces () if err! = nil {return nil, fmt.Errorf ("net.Interfaces failed, err:% s", err.Error ())} var ip = make ([] string, 0) for I: = 0; I < len (netInterfaces) ITunes + {if (netInterfaces [I] .Flags & net.FlagUp)! = 0 {addrs, _: = netInterfaces [I] .Addrs () for _, address: = range addrs {if ipnet, ok: = address. (* net.IPNet) Ok & &! ipnet.IP.IsLoopback () {if ipnet.IP.To4 ()! = nil & & ipnet.IP.String ()! = "" {ip = append (ip Ipnet.IP.String ()} return ip, nil} so far I believe you have a deeper understanding of "the method that GetIP uses to obtain effective intranet IP", so you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Effective method content learning practical deeper interested practical practical easy to operate more friends websites channels inquiries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MySQL Shulou Tech Info vpn Microsoft