private static string GetcnIp16Range(Dictionary <IPAddress, int> ipv4Subnets) { var sb = new StringBuilder("{\n"); var masterNetSet = new SortedSet <uint>(); foreach (var ipv4Subnet in ipv4Subnets) { var p = new IPv4Subnet(ipv4Subnet.Key, ipv4Subnet.Value); if (ipv4Subnet.Value < 1 << 14) { masterNetSet.Add(IPv4Subnet.IPv42UintBE(p.FirstIP) >> 14); } } var masterNet = new List <uint>(masterNetSet.Count); foreach (var x in masterNetSet) { masterNet.Add(x); } //masterNet.Sort(); foreach (var x in masterNet) { sb.Append(@"0x"); sb.Append(Convert.ToString(x, 16)); sb.Append(@":1,"); } sb.Remove(sb.Length - 1, 1); sb.Append("\n};"); return(sb.ToString()); }
private static string GetcnIpRange(Dictionary <IPAddress, int> ipv4Subnets) { var sb = new StringBuilder("[\n{"); uint startNum = 0; var comma = @""; foreach (var ipv4Subnet in ipv4Subnets) { var p = new IPv4Subnet(ipv4Subnet.Key, ipv4Subnet.Value); while (IPv4Subnet.IPv42UintBE(p.FirstIP) >> 24 > startNum) { ++startNum; sb.Append(@"},{"); comma = @""; } sb.Append(comma); sb.Append(@"0x"); sb.Append(Convert.ToString(IPv4Subnet.IPv42UintBE(p.FirstIP) / 256, 16)); sb.Append(@":"); sb.Append(ipv4Subnet.Value / 256); comma = @","; } sb.Append("}\n];"); return(sb.ToString()); }
private static string GetACLCNIP(Dictionary <IPAddress, int> ipv4Subnets) { var sb = new StringBuilder(); foreach (var ipv4Subnet in ipv4Subnets) { var p = new IPv4Subnet(ipv4Subnet.Key, ipv4Subnet.Value); sb.AppendLine($@"{p.FirstIP}/{p.CIDR}"); } return(sb.ToString()); }
public static void Writedelroute(Dictionary <IPAddress, int> ipv4Subnets) { using (var fileS = new FileStream(Path + Filename_delroute, FileMode.Create, FileAccess.Write)) { using (var sw = new StreamWriter(fileS, UTF8withoutBOM)) { foreach (var ipv4Subnet in ipv4Subnets) { var p = new IPv4Subnet(ipv4Subnet.Key, ipv4Subnet.Value); sw.WriteLine($@"delete {p.FirstIP} mask {p.Netmask} default METRIC default IF default"); } } } }
public static void Writecnip(Dictionary <IPAddress, int> ipv4Subnets) { using (var fileS = new FileStream(Path + Filename_cnip, FileMode.Create, FileAccess.Write)) { using (var sw = new StreamWriter(fileS, UTF8withoutBOM)) { foreach (var ipv4Subnet in ipv4Subnets) { var p = new IPv4Subnet(ipv4Subnet.Key, ipv4Subnet.Value); sw.WriteLine($@"{p.FirstIP} {p.LastIP}"); } } } }
private static KeyValuePair <IPAddress, int>?GetCNIPv4InfoFromIpipNetLine(string str) { if (string.IsNullOrWhiteSpace(str)) { return(null); } var reg = new Regex("^(.+)/(.+)$"); var match = reg.Match(str); if (match.Groups.Count == 3) { var ipv4 = IPAddress.Parse(match.Groups[1].Value); var hosts = IPv4Subnet.CIDR2Hosts(Convert.ToInt32(match.Groups[2].Value)); return(new KeyValuePair <IPAddress, int>(ipv4, hosts)); } return(null); }