protected override void ProcessRecord() { base.ProcessRecord(); try { IPNetwork n = null; if (!string.IsNullOrEmpty(Netmask)) { n = IPNetwork.Parse(IPAddress, Netmask); } else if (CidrMask.HasValue) { n = IPNetwork.Parse(IPAddress, CidrMask.Value); } else { n = IPNetwork.Parse(IPAddress); } Information($"Ip Address {n.FirstUsable} with Mask {n.Cidr} value add {n}"); WriteObject(n); } catch (Exception ex) { Error(ex, ErrorCategory.ResourceUnavailable, Properties.Resources.IPNetworkCalculateCidrFailure, IPAddress); } }
public static bool IpMatch(string ip1, string ip2) { string rgxString = @"^(((\d)|(\d\d)|((1)\d\d)|(2[0-4]\d)|(25[0-5])).){3}((\d)|(\d\d)|((1)\d\d)|(2[0-4]\d)|(25[0-5]))$"; Regex rgx = new Regex(rgxString); if (!rgx.IsMatch(ip1)) { throw new Exception("invalid argument: ip1 in IPMatch() function is not an IP address."); } IPNetwork ipNetwork2 = IPNetwork.Parse(ip2); if (!(ipNetwork2.AddressFamily == AddressFamily.InterNetwork || ipNetwork2.AddressFamily == AddressFamily.InterNetworkV6)) { throw new Exception("invalid argument: ip2 in IPMatch() function is neither an IP address nor a CIDR."); } IPNetwork ipNetwork1 = IPNetwork.Parse(ip1); if (ipNetwork1.Equals(ipNetwork2)) { return(true); } return(ipNetwork1.Netmask.Equals(IPAddress.Parse(ip2))); }
public Task <AppResponse.Response <GeoPositionResponse> > GetGeoPosition(string ipAddress) { if (string.IsNullOrEmpty(ipAddress)) { throw new CustomException(ResponseCodes.INVALID_PARAMETER, EmptyIpAddressHaveBeenPassedErrorMessage); } try { using (IDbService dbService = new DbService(_db).DbServiceInstance) { var getInformation = await dbService.GeoLite.Get() } var g = IPNetwork.Parse(ipAddress, 8); } catch (Exception e) { Console.WriteLine(e); throw; } throw new System.NotImplementedException(); }
public static void Main(string[] args) { string target = args[0]; string username = args[1]; string hash = args[2]; // Parse CIDR IPNetwork ipn = IPNetwork.Parse(target); IPAddressCollection ips = IPNetwork.ListIPAddress(ipn); // Parallel ForEach to iterate over IP's from CIDR block Parallel.ForEach(ips, (ip) => { try { string[] arguments; string targetIP = ip.ToString(); arguments = new string[3] { targetIP, username, hash }; SharpInvoke_SMBExec.Program.Main(arguments); } catch (Exception e) { Console.WriteLine(e); } }); }
public bool IsInSubnet(Subnet source, Subnet toTest) { IPNetwork sourceSubnet = IPNetwork.Parse(source.IPAddress, source.Cidr); IPNetwork testSubnet = IPNetwork.Parse(toTest.IPAddress, toTest.Cidr); return(sourceSubnet.Contains(testSubnet)); }
protected override object GetDataFromSource() { List <string> IPresult = new List <string>(); List <IPNetwork> result = new List <IPNetwork>(); using (WebClient client = new MyWebClient()) { try { string data = client.DownloadString("https://www.cloudflare.com/ips-v4"); string line = null; StringReader strReader = new StringReader(data); while ((line = strReader.ReadLine()) != null) { IPresult.Add(line); } } catch (Exception ex) { ErrorLogger.Log(ex); } } foreach (var ip in IPresult) { result.Add(IPNetwork.Parse(ip)); } return(result); }
private void AddListenIpToList() { string hostName = Dns.GetHostName(); var addressList = Dns.GetHostAddresses(hostName); IPNetwork localnet192 = IPNetwork.Parse("192.168.0.0/16"); IPNetwork localnet172 = IPNetwork.Parse("172.16.0.0/12"); IPNetwork localnet169 = IPNetwork.Parse("169.254.0.0/16"); IPNetwork localnet10 = IPNetwork.Parse("10.0.0.0/8"); foreach (IPAddress ip in addressList.Distinct().ToList()) { if (ip.IsIPv6LinkLocal || ip.IsIPv6Multicast || ip.IsIPv6SiteLocal || ip.IsIPv6Teredo) { continue; } if (localnet192.Contains(ip) || localnet172.Contains(ip) || localnet169.Contains(ip) || localnet10.Contains(ip)) { continue; } if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { listListenIP.Items.Add(ip); } if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { listListenIP.Items.Add(ip); } } }
public void TestReset() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/29"); using (IPAddressCollection ips = ipn.ListIPAddress()) { ips.Reset(); } }
public void TestCountIPAddress() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/29"); using (IPAddressCollection ips = ipn.ListIPAddress()) { Assert.AreEqual(8, ips.Count, "Count"); } }
public void Test_ipv6_CountIPAddress() { IPNetwork ipn = IPNetwork.Parse("::/125"); using (IPAddressCollection ips = ipn.ListIPAddress()) { Assert.AreEqual(8, ips.Count, "Count"); } }
public List <IpRangeViewModel> GetSubnetList(string ipFilePath = null) { if (string.IsNullOrEmpty(ipFilePath)) { ipFilePath = HostingEnvironment.MapPath("~/App_Data/"); } var result = new List <IpRangeViewModel>(); // Load Azure ip range data string ipFileList = ConfigurationManager.AppSettings["AzureIpRangeFileList"]; foreach (string filePath in ipFileList.Split(';')) { var xmlDoc = new XmlDocument(); xmlDoc.Load(ipFilePath + @"\IpRangeFiles\Azure\" + filePath); var root = xmlDoc.DocumentElement; foreach (XmlElement ele in root) { string region = ele.GetAttribute("Name"); var ipRange = new IpRangeViewModel { Cloud = "Azure", Region = region, Subnet = new List <string>() }; foreach (XmlElement xe in ele) { string subnet = xe.GetAttribute("Subnet"); ipRange.Subnet.Add(subnet); var network = IPNetwork.Parse(subnet); ipRange.TotalIpCount += network.Total; } result.Add(ipRange); } } return(result); }