I have a list of user IP addresses like following:
user 1:
192.168.1.1
192.168.1.2
192.168.1.3
user 2:
192.168.1.1
192.168.1.2
192.168.1.3
172.0.0.1
172.0.0.5
174.5.5.15
Now what I'd like to do here is to filter out all the IP's that are obviously from the same subnet/coming from the same PC/City.
I'm only using local IP's as an example here.
After filtering I would be left with the following:
For user 1 it is enough for me to have only 1 IP from each subnet like following:
192.168.1.1 => all other IP's would be removed, only one would be left
from that specific subnet
For user 2:
192.168.1.1
172.0.0.1
174.5.5.15
For the user 2 I'm left with 3 IP's since 192.168.. and 172.0.. had multiple ip's from that range.
Now my idea is to use a criteria for the first two numbers of the IP to be compared. For example:
192.168.0.1
192.168.0.2
192.168.0.6
These 3 have same first two numbers (192.168), thus I can consider them as duplicates and they should be removed. Which ever 1 of the IP's is left here from these is irrelevant, what matters is is that only 1 is left.
This would result in 1 ip to be left, for example:
192.168.0.1 (again doesn't matter which one is left, just that 1 is left!)
Now onto the part with code. I have a class structure like following:
public class SortedUser
{
public string Email { get; set; }
public List<IpInfo> IPAndCountries = new List<IpInfo>();
}
And IPInfo class looks like this:
public class IpInfo
{
public string Ip { get; set; }
}
Can someone help me out with this now? How can I do it in most easiest way?