Пример #1
0
 /// <summary>
 /// Evaluates the function on a scalar argument.
 /// </summary>
 /// <param name="Argument">Function argument.</param>
 /// <param name="Variables">Variables collection.</param>
 /// <returns>Function result.</returns>
 public override IElement EvaluateScalar(IElement Argument, Variables Variables)
 {
     if (Argument.AssociatedObjectValue is IPAddress IP ||
         IPAddress.TryParse(Argument.AssociatedObjectValue?.ToString() ?? string.Empty, out IP))
     {
         return(new StringValue(WhoIsClient.Query(IP).Result));
     }
Пример #2
0
        /// <summary>
        /// Appends WHOIS information to a Markdown document.
        /// </summary>
        /// <param name="Markdown">Markdown being built.</param>
        /// <param name="RemoteEndpoint">Remote Endpoint.</param>
        /// <returns>WHOIS information found, or <see cref="string.Empty"/> if no information found.</returns>
        public static async Task <string> AppendWhoIsInfo(StringBuilder Markdown, string RemoteEndpoint)
        {
            if (IPAddress.TryParse(RemoteEndpoint, out IPAddress Address))
            {
                try
                {
                    string s = await WhoIsClient.Query(Address);

                    Markdown.AppendLine();
                    Markdown.AppendLine();
                    Markdown.AppendLine("WHOIS Information:");
                    Markdown.AppendLine();
                    Markdown.AppendLine("```");
                    Markdown.AppendLine(s);
                    Markdown.AppendLine("```");

                    return(s);
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }

            return(string.Empty);
        }
Пример #3
0
 /// <summary>
 /// Evaluates the function on a scalar argument.
 /// </summary>
 /// <param name="Argument">Function argument.</param>
 /// <param name="Variables">Variables collection.</param>
 /// <returns>Function result.</returns>
 public override IElement EvaluateScalar(string Argument, Variables Variables)
 {
     if (IPAddress.TryParse(Argument, out IPAddress IP))
     {
         return(new StringValue(WhoIsClient.Query(IP).Result));
     }
     else
     {
         throw new ScriptRuntimeException("Not an IP address.", this);
     }
 }
Пример #4
0
        /// <summary>
        /// Gets an annotated Remote endpoint state object, if one is available.
        /// </summary>
        /// <param name="RemoteEndpoint">Remote Endpoint.</param>
        /// <returns>Annotated state object, if available. Null otherwise.</returns>
        public async Task <RemoteEndpoint> GetAnnotatedStateObject(string RemoteEndpoint)
        {
            string         s  = this.RemovePort(RemoteEndpoint);
            RemoteEndpoint EP = await this.GetStateObject(s, string.Empty, false);

            if (EP is null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(EP.WhoIs))
            {
                if (IPAddress.TryParse(s, out IPAddress Address) && !IPAddress.IsLoopback(Address))
                {
                    EP.WhoIs = await WhoIsClient.Query(Address);
                }

                await EP.Annotate();

                await Database.Update(EP);
            }

            return(EP);
        }
Пример #5
0
        public async Task Test_05_LACNIC()
        {
            string s = await WhoIsClient.Query(IPAddress.Parse("192.230.79.221"));

            Console.Out.WriteLine(s);
        }
Пример #6
0
        public async Task Test_04_AFRINIC()
        {
            string s = await WhoIsClient.Query(IPAddress.Parse("42.1.1.1"));

            Console.Out.WriteLine(s);
        }
Пример #7
0
        public async Task Test_03_ARIN()
        {
            string s = await WhoIsClient.Query(IPAddress.Parse("69.192.66.35"));

            Console.Out.WriteLine(s);
        }
Пример #8
0
        public async Task Test_02_RIPE()
        {
            string s = await WhoIsClient.Query(IPAddress.Parse("81.236.63.162"));

            Console.Out.WriteLine(s);
        }
Пример #9
0
        public async Task Test_01_APNIC()
        {
            string s = await WhoIsClient.Query(IPAddress.Parse("172.217.20.35"));

            Console.Out.WriteLine(s);
        }