diff --git a/cmd/action.go b/cmd/action.go index 9785fe4..71f0c07 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -109,6 +109,15 @@ var CliAction = func(ctx *cli.Context) error { } } + //If the network interface flag is called + // Then all the network interfaces are displayed + if NetworkInterface { + err := p2p.ViewNetworkInterface() + if err != nil { + fmt.Print(err) + } + } + return nil } diff --git a/cmd/flags.go b/cmd/flags.go index fc6c4fe..fcc106d 100644 --- a/cmd/flags.go +++ b/cmd/flags.go @@ -19,6 +19,7 @@ var ( UpdateServerList bool ServerList bool SetDefaultConfig bool + NetworkInterface bool ) var AppConfigFlags = []cli.Flag{ @@ -103,4 +104,10 @@ var AppConfigFlags = []cli.Flag{ EnvVars: []string{"SET_DEFAULT_CONFIG"}, Destination: &SetDefaultConfig, }, + &cli.BoolFlag{ + Name: "NetworkInterfaces", + Usage: "Shows the network interface in your computer", + EnvVars: []string{"NETWORK_INTERFACE"}, + Destination: &NetworkInterface, + }, } \ No newline at end of file diff --git a/config/config.go b/config/config.go index e3cc0be..76f6b65 100644 --- a/config/config.go +++ b/config/config.go @@ -13,6 +13,7 @@ var ( "DefaultDockerFile": "/home/akilan/Documents/p2prendering/p2p-redering-computation/server/docker/containers/docker-ubuntu-sshd/", "SpeedTestFile":"/etc/p2p-rendering/50.bin", "NetworkInterface": "wlp0s20f3", + "NetworkInterfaceIPV6Index": "1", } configName = "config" configType = "json" @@ -26,6 +27,7 @@ type Config struct { DefaultDockerFile string SpeedTestFile string NetworkInterface string + NetworkInterfaceIPV6Index int } // Exists reports whether the named file or directory exists. @@ -53,6 +55,7 @@ func SetDefaults() error { defaults["DockerContainers"] = defaultPath + "server/docker/containers/" defaults["SpeedTestFile"] = defaultPath + "p2p/50.bin" defaults["NetworkInterface"] = "wlp0s20f3" + defaults["NetworkInterfaceIPV6Index"] = "2" //Paths to search for config file configPaths = append(configPaths, defaultPath) diff --git a/p2p/ip_table.json b/p2p/ip_table.json index 865ad71..7ba6cde 100644 --- a/p2p/ip_table.json +++ b/p2p/ip_table.json @@ -3,7 +3,7 @@ { "ipv4": "", "ipv6": "2001:8f8:172d:ee93:7588:ad57:c351:3309", - "latency": 462096, + "latency": 1213198, "download": 0, "upload": 0 } diff --git a/p2p/iptable.go b/p2p/iptable.go index 9467a77..d7cf46e 100644 --- a/p2p/iptable.go +++ b/p2p/iptable.go @@ -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 { diff --git a/p2p/iptable_test.go b/p2p/iptable_test.go index 6248012..971ccd8 100644 --- a/p2p/iptable_test.go +++ b/p2p/iptable_test.go @@ -58,3 +58,10 @@ func TestIpAddresses_RemoveDuplicates(t *testing.T) { } } + +func TestViewNetworkInterface(t *testing.T) { + err := ViewNetworkInterface() + if err != nil { + t.Error() + } +}