private IPAddress[] GetDefaultAddresses() { var l = new List <IPAddress>(); var hosts = GetHostAddresses(); if (hosts != null) { foreach (var host in hosts) { IPNetwork ip; if (IPNetwork.TryParse(host.ToString(), out ip)) { var addresses = IPNetwork.ListIPAddress(ip); if (addresses != null) { foreach (var address in addresses) { l.Add(address); } } } } } return(l.ToArray()); }
public FindDevices() { InitializeComponent(); DataContext = this; Closed += FindDevices_Closed; Properties.Settings.Default.Upgrade(); Properties.Settings.Default.Save(); // Load Address Range AddressFrom = Properties.Settings.Default.AddressFrom; AddressTo = Properties.Settings.Default.AddressTo; if (string.IsNullOrEmpty(AddressFrom) || string.IsNullOrEmpty(AddressTo)) { var hostAddress = GetHostAddress(); if (hostAddress != null) { IPNetwork ip; if (IPNetwork.TryParse(hostAddress.ToString(), out ip)) { var addresses = IPNetwork.ListIPAddress(ip); if (addresses != null) { AddressFrom = addresses.First().ToString(); AddressTo = addresses.Last().ToString(); } } } } // Load Port Range PortFrom = Properties.Settings.Default.PortFrom; PortTo = Properties.Settings.Default.PortTo; }
public VLan(string cidr) { Cidr = cidr; _ipnetwork = IPNetwork.Parse(Cidr); _ipAddresses = _ipnetwork.ListIPAddress(FilterEnum.Usable); }
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 TestReset() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/29"); using (IPAddressCollection ips = ipn.ListIPAddress()) { ips.Reset(); } }
public void Test_ipv6_CountIPAddress() { IPNetwork ipn = IPNetwork.Parse("::/125"); using (IPAddressCollection ips = ipn.ListIPAddress()) { Assert.AreEqual(8, ips.Count, "Count"); } }
public void TestEnumerableCurrent() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/31"); IEnumerable ips = ipn.ListIPAddress(); Assert.IsNotNull(ips.GetEnumerator()); }
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 void Test_ipv6_Reset() { IPNetwork ipn = IPNetwork.Parse("::/125"); using (IPAddressCollection ips = IPNetwork.ListIPAddress(ipn)) { ips.Reset(); } }
public void Test_ipv6_OutOfRangeIPAddress() { IPNetwork ipn = IPNetwork.Parse("::/125"); using (var ips = IPNetwork.ListIPAddress(ipn)) { Console.Write("This is out of range : {0} ", ips[8]); } }
public void TestOutOfRangeIPAddress() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/29"); using (var ips = IPNetwork.ListIPAddress(ipn)) { Console.Write("This is out of range : {0} ", ips[8]); } }
public void Test_ipv6_CountIPAddress2() { IPNetwork ipn = IPNetwork.Parse("::/0"); var max = BigInteger.Pow(2, 128); using (IPAddressCollection ips = ipn.ListIPAddress()) { Assert.AreEqual(max, ips.Count, "Count"); } }
public void TestEnumeratorIterate() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/31"); IEnumerator ips = ipn.ListIPAddress(); while (ips.MoveNext()) { Assert.IsNotNull(ips.Current); } }
static void Main(string[] args) { Parser.Default.ParseArguments <Options>(args) .WithParsed <Options>(o => { string cidr = o.Cidr; string outfile = o.Outfile; int port = o.Port; bool ssl = o.SSL; string useragent = o.UserAgent; string proto; if (ssl == true) { proto = "https"; } else { proto = "http"; } IPNetwork ipn = IPNetwork.Parse(cidr); IPAddressCollection ips = IPNetwork.ListIPAddress(ipn); Console.WriteLine("Scanning {0} IPs", ips.Count); Hashtable table = DefaultCreds.GetHashTable(); string html = null; html += HTML.GetHeader(); Parallel.ForEach(ips, ip => { string url = proto + "://" + ip + ":" + port; string resp = HTTP.MakeRequest(url, useragent); string title = HTTP.GetTitle(resp); Image screenshot = Screenshot.Capture(url); html += HTML.GetTitle(title); html += HTML.GetAddress(url); foreach (DictionaryEntry item in table) { if (title.ToLower().Contains(item.Key.ToString())) { string creds = HTML.GetDefaultCreds(table[item.Key].ToString()); html += creds; } } html += HTML.GetImg(Convert.ToBase64String(ImageConverter.ToByteArray(screenshot))); }); html += HTML.GetFooter(); File.Write(outfile, html); }); }
static void Main(string[] args) { string cidr = null; bool showhelp = false; var opts = new OptionSet() { { "cidr=", " --cidr 192.168.1.0/24", v => cidr = v }, { "h|?|help", "Show available options", v => showhelp = v != null }, }; try { opts.Parse(args); } catch (OptionException e) { Console.WriteLine(e.Message); } if (showhelp) { Console.WriteLine("RTFM"); opts.WriteOptionDescriptions(Console.Out); Console.WriteLine("[*] Example: MSSQLUDPScanner.exe --cidr 192.168.1.0/24"); return; } // Parse CIDR IPNetwork ipn = IPNetwork.Parse(cidr); IPAddressCollection ips = IPNetwork.ListIPAddress(ipn); Parallel.ForEach(ips, ip => { try { var udpClient = new UdpClient(); IPEndPoint ep = new IPEndPoint((ip), 1434); udpClient.Connect(ep); int number = 3; byte[] sendBytes = BitConverter.GetBytes(number); udpClient.Client.ReceiveTimeout = 10000; udpClient.Client.Blocking = true; udpClient.Send(sendBytes, sendBytes.Length); IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); Byte[] receiveBytes = udpClient.Receive(ref RemoteIpEndPoint); string returnData = Encoding.ASCII.GetString(receiveBytes); string results = returnData.ToString(); Console.WriteLine("IP: " + ip + " " + results.Replace(';', ' ') + "\r\n"); udpClient.Close(); } catch (Exception) { // Do not print errors } }); }
public void Test_ipv6_EnumeratorCurrent() { IPNetwork ipn = IPNetwork.Parse("::/127"); IEnumerator ips = ipn.ListIPAddress(); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); }
public void Test_ipv6_EnumeratorIterate() { IPNetwork ipn = IPNetwork.Parse("::/127"); IEnumerator ips = IPNetwork.ListIPAddress(ipn); while (ips.MoveNext()) { Assert.IsNotNull(ips.Current); } }
public void Scan(string iprange) { IPNetwork ipnetwork = IPNetwork.Parse(iprange); firstusable = ipnetwork.FirstUsable; lastusable = ipnetwork.LastUsable; usablenumber = ipnetwork.Usable; ipac = IPNetwork.ListIPAddress(ipnetwork); StartScan(); }
private static void ListIPAddress(ProgramContext ac) { foreach (IPNetwork ipnetwork in ac.Networks) { foreach (IPAddress ipaddress in IPNetwork.ListIPAddress(ipnetwork)) { Console.WriteLine("{0}", ipaddress.ToString()); } } }
public void TestEnumeratorCurrent() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/31"); IEnumerator ips = IPNetwork.ListIPAddress(ipn); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); }
public void Test_ipv6_EnumeratorCurrentOor() { IPNetwork ipn = IPNetwork.Parse("::/127"); IEnumerator ips = ipn.ListIPAddress(); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); Console.WriteLine("This is out of range : {0} ", ips.Current); }
public void TestEnumeratorCurrentOor() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/31"); IEnumerator ips = IPNetwork.ListIPAddress(ipn); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsNotNull(ips.Current); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); Console.WriteLine("This is out of range : {0} ", ips.Current); }
public void Test_ipv6_EnumeratorFailed() { IPNetwork ipn = IPNetwork.Parse("::/125"); using (IEnumerator<IPAddress> ips = ipn.ListIPAddress()) { ips.Reset(); while (ips.MoveNext()) { Assert.IsNotNull(ips.Current); } Console.WriteLine("This is out of range : {0}", ips.Current); } }
/*NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(AddressChangedCallback);*/ public static List <string> GetAllIps() { List <string> l_Ips = new List <string>(); IPNetwork ipn = IPNetwork.Parse(GetLocalAddr() + "/" + GetCidr(GetNetmask())); LukeSkywalker.IPNetwork.IPAddressCollection ips = IPNetwork.ListIPAddress(ipn); foreach (IPAddress ip in ips) { l_Ips.Add(ip.ToString()); } return(l_Ips); }
public static IEnumerable <string> ExpandIpAddressRangeSubnet(string address) { var addressSubnet = address.Split('/'); if (addressSubnet.Count() == 1) { return(new[] { address }); } var network = IPNetwork.Parse(address); return(IPNetwork.ListIPAddress(network).Select(ip => ip.ToString())); }
public IObservable <Host> FindAddresses(string network, int port) { IPNetwork ipNetwork = IPNetwork.Parse(network); return(ipNetwork.ListIPAddress() .Where(item => !localAddresses.Contains(item)) .ToObservable() .SelectMany( item => Observable.Start(async() => (await ScanPort(item, port).ConfigureAwait(false), item), scheduler) .Merge() .Where(pair => pair.Item1) .Select(pair => new Host(GetHostName(pair.Item2), pair.Item2)))); }
public void Execute(Guid profileId, string subnetId) { AwsProfile profile = _profileRepository.Find(profileId); if (profile == null) { return; } INetworkService networkService = _awsClientFactory.GetClient(profile).NetworkService; string cidrRange; try { cidrRange = networkService.GetCidrBySubnetId(subnetId); } catch (AmazonEC2Exception e) { Debug.WriteLine(e.Message); return; } if (_ipRangeRepository.FindAll().Any(x => x.Cidr == cidrRange)) { return; } DateTime utcNow = DateTime.UtcNow; IPNetwork network = IPNetwork.Parse(cidrRange); List <SubnetIpAddress> subnetIpAddresses = IPNetwork.ListIPAddress(network) .Skip(5) // Amazon reserves the first four IP addresses... (x.x.x.1 - x.x.x.4) .Select(x => new SubnetIpAddress { Address = x, IsInUse = false, LastUpdateTime = utcNow }).ToList(); if (subnetIpAddresses.Any()) { subnetIpAddresses.RemoveAt(subnetIpAddresses.Count - 1); // and last IP address. } var ipRange = new IPRange { AwsProfileId = profileId, Cidr = cidrRange, Addresses = subnetIpAddresses.ToDictionary(x => x.Address.ToString()) }; _ipRangeRepository.Add(ipRange); }
public void TestEnumeratorMoveNext2() { IPNetwork ipn = IPNetwork.Parse("192.168.1.0/31"); using (IEnumerator <IPAddress> ips = IPNetwork.ListIPAddress(ipn)) { Assert.IsTrue(ips.MoveNext()); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); ips.Reset(); Assert.IsTrue(ips.MoveNext()); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); } }
public void Test_ipv6_EnumeratorMoveNext2() { IPNetwork ipn = IPNetwork.Parse("::/127"); using (IEnumerator <IPAddress> ips = IPNetwork.ListIPAddress(ipn)) { Assert.IsTrue(ips.MoveNext()); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); ips.Reset(); Assert.IsTrue(ips.MoveNext()); Assert.IsTrue(ips.MoveNext()); Assert.IsFalse(ips.MoveNext()); } }
public void Test_ipv6_AtIndexIPAddress() { IPNetwork ipn = IPNetwork.Parse("::/125"); using (var ips = IPNetwork.ListIPAddress(ipn)) { Assert.AreEqual("::", ips[0].ToString(), "0"); Assert.AreEqual("::1", ips[1].ToString(), "1"); Assert.AreEqual("::2", ips[2].ToString(), "2"); Assert.AreEqual("::3", ips[3].ToString(), "3"); Assert.AreEqual("::4", ips[4].ToString(), "4"); Assert.AreEqual("::5", ips[5].ToString(), "5"); Assert.AreEqual("::6", ips[6].ToString(), "6"); Assert.AreEqual("::7", ips[7].ToString(), "7"); } }