예제 #1
0
파일: Network.cs 프로젝트: phonegi/network
        public static List<Network> LoadFromFile(string filename)
        {
            List<Network> networks = new List<Network>();
            StreamReader reader;
            string pattern;
            string line;
            int lineNumber = 1;
            Match match;
            IPAddress ipAddress;
            string subnet;
            Network network;

            reader = File.OpenText(filename);
            //string pattern = @"(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.)(?:(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))/(?:([1-2][0-9]|3[0-2]|[0-9]))";
            pattern = @"((?<ip>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)))/(?<subnet>([1-2][0-9]|3[0-2]|[0-9])))";

            while (!reader.EndOfStream) {
                line = reader.ReadLine();
                if (line.Contains("subnet")) continue;
                match = Regex.Match(line, pattern);
                if (match.Success) {
                    ipAddress = IPAddress.Parse(match.Groups["ip"].Value);
                    subnet = match.Groups["subnet"].Value;
                    network = new Network(ipAddress, subnet);
                    try {
                        networks.Add(network);
                    }
                    catch {

            #if DEBUG
                        Console.WriteLine("{0} is a duplicate. Line {1}", match.Groups["ip"].Value, lineNumber);
            #endif

                    }
                }

            #if DEBUG
                else {
                    Console.WriteLine("Skipping line {0}", lineNumber);
                }
            #endif

                lineNumber++;
            }

            #if DEBUG
            Console.WriteLine("Last Line {0}", lineNumber);
            #endif

            reader.Close();
            return networks;
        }
예제 #2
0
파일: Network.cs 프로젝트: phonegi/network
 public bool Overlap(Network network)
 {
     if (network.LastHostValue < NetworkValue) return false;
     if (network.NetworkValue < NetworkValue && NetworkValue < network.LastHostValue) return true;
     if (network.NetworkValue < NetworkValue && LastHostValue < network.LastHostValue) return true;
     if (NetworkValue < network.NetworkValue && network.LastHostValue < LastHostValue) return true;
     if (network.NetworkValue < LastHostValue && LastHostValue < network.LastHostValue) return true;
     if (LastHostValue < network.NetworkValue) return false;
     return true;
 }