示例#1
0
        private static async Task Query(string addr, ArinClient client)
        {
            var response = await client.Query(IPAddress.Parse(addr));

            if (response is ErrorResponse error)
            {
                Console.WriteLine($"{error.ErrorCode}: {error.Title}");
                return;
            }

            if (response is IpResponse ip)
            {
                DisplayEntities(ip.Entities, "");

                Console.WriteLine();

                if (DisplayDetails)
                {
                    List <(string name, object value)> props = Explode(ip);

                    foreach (var(name, value) in props)
                    {
                        Console.WriteLine($"{name}: {value}");
                    }

                    Console.WriteLine();
                }
            }
        }
示例#2
0
        public void TestIpNotFound()
        {
            var arinClient = new ArinClient();
            var response   = arinClient.QueryIpAsync(IPAddress.Parse("108.33.73.20")).Result;

            Assert.IsNull(response);
        }
示例#3
0
        public async Task TestIpNotFound()
        {
            var arinClient = new ArinClient();
            var response   = await arinClient.QueryIpAsync(IPAddress.Parse("108.33.73.20"));

            Assert.IsNull(response);
        }
示例#4
0
        static async Task Main(string[] args)
        {
            string addr = null;

            if (args.Length > 0)
            {
                addr = args[0];

                if (args.Length > 1)
                {
                    DisplayDetails = true;
                }
            }

            var client = new ArinClient();

            int thrown = 0;

            if (string.IsNullOrWhiteSpace(addr))
            {
                Console.WriteLine("Usage: ArinConsoleClient.exe ip-addr|path-to-file.txt");
            }
            else if (File.Exists(addr))
            {
                var file = File.ReadAllLines(addr);

                for (var i = 0; i < file.Length; i++)
                {
                    var ip = file[i];

                    Console.WriteLine($"# {i} = {ip}");

                    try
                    {
                        await Query(ip, client);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);

                        if (thrown++ > 10)
                        {
                            throw;
                        }
                    }
                }
            }
            else
            {
                await Query(addr, client);
            }
        }
示例#5
0
        public void TestIpFound()
        {
            var arinClient = new ArinClient();
            var ipResponse = arinClient.QueryIpAsync(IPAddress.Parse("69.63.176.0")).Result;

            Assert.IsNotNull(ipResponse);
            Assert.IsNotNull(ipResponse.Network);

            Assert.IsTrue(ipResponse.Network.TermsOfUse.StartsWith("http"));
            Assert.IsNotNull(ipResponse.Network.RegistrationDate.Value);
            Assert.IsNotNull(ipResponse.Network.NetBlocks.NetBlock);
            Assert.IsNotNull(ipResponse.Network.NetBlocks.NetBlock.CidrLength.Value);
            Assert.IsNotNull(ipResponse.Network.NetBlocks.NetBlock.Description);

            Assert.IsNotNull(ipResponse.Network.OrgRef.Name);
            Assert.AreEqual(ipResponse.Network.OrgRef.Name, "Facebook, Inc.");

            var organizationHandle   = ipResponse.Network.OrgRef.Handle;
            var organizationResponse = arinClient.QueryResourceAsync(organizationHandle, ArinClient.ResourceType.Organization).Result;

            Assert.IsNotNull(organizationResponse);
            Assert.AreEqual(organizationResponse.Organization.City.Value, "Menlo Park");
        }