adds ipv6 index to config and a cli command to view network interface
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
{
|
||||
"ipv4": "",
|
||||
"ipv6": "2001:8f8:172d:ee93:7588:ad57:c351:3309",
|
||||
"latency": 462096,
|
||||
"latency": 1213198,
|
||||
"download": 0,
|
||||
"upload": 0
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ func GetCurrentIPV6()(string,error){
|
||||
if addresses[1].String() == "" {
|
||||
return "",errors.New("IPV6 address not detected")
|
||||
}
|
||||
IP,_,err := net.ParseCIDR(addresses[1].String())
|
||||
IP,_,err := net.ParseCIDR(addresses[Config.NetworkInterfaceIPV6Index].String())
|
||||
if err != nil {
|
||||
return "",err
|
||||
}
|
||||
@@ -194,6 +194,31 @@ func GetCurrentIPV6()(string,error){
|
||||
return IP.String(), nil
|
||||
}
|
||||
|
||||
// ViewNetworkInterface This function is created to view the network interfaces available
|
||||
func ViewNetworkInterface() error {
|
||||
ifaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
addrs, err := i.Addrs()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for index, a := range addrs {
|
||||
switch v := a.(type) {
|
||||
case *net.IPAddr:
|
||||
fmt.Printf("(%v) %v : %s (%s)\n", index, i.Name, v, v.IP.DefaultMask())
|
||||
|
||||
case *net.IPNet:
|
||||
fmt.Printf("(%v) %v : %s \n", index, i.Name, v)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ip4or6 Helper function to check if the IP address is IPV4 or
|
||||
//IPV6 (https://socketloop.com/tutorials/golang-check-if-ip-address-is-version-4-or-6)
|
||||
func Ip4or6(s string) string {
|
||||
|
||||
@@ -58,3 +58,10 @@ func TestIpAddresses_RemoveDuplicates(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestViewNetworkInterface(t *testing.T) {
|
||||
err := ViewNetworkInterface()
|
||||
if err != nil {
|
||||
t.Error()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user