function to remove duplicates in IP table

This commit is contained in:
2021-04-16 20:35:51 +04:00
parent 4e22572c7b
commit 9ec1329af9
4 changed files with 49 additions and 35 deletions

View File

@@ -86,5 +86,36 @@ func PrintIpTable() error {
"-----------\n",table.IpAddress[i].Ipv4,
table.IpAddress[i].Latency,table.IpAddress[i].Download,table.IpAddress[i].Upload)
}
return nil
}
// RemoveDuplicates This is a temporary fix current functions failing to remove
// Duplicate IP addresses from local IP table
func RemoveDuplicates() error {
table, err := ReadIpTable()
if err != nil {
return err
}
var NoDuplicates IpAddresses
for i, _:= range table.IpAddress {
Exists := false
for k := range NoDuplicates.IpAddress {
if NoDuplicates.IpAddress[k].Ipv4 == table.IpAddress[i].Ipv4 {
Exists = true
break
}
}
if Exists {
continue
}
NoDuplicates.IpAddress = append(NoDuplicates.IpAddress, table.IpAddress[i])
}
if err := NoDuplicates.WriteIpTable(); err != nil {
return nil
}
return nil
}