Exemplo n.º 1
0
        internal static void ResolveIp(string IpAddress)
        {
            string IPGeolocationApiUrl;

            IPGeolocationApiUrl = "http://ip-api.com/json/" + IpAddress;
            // Tantalizes C# version of GET request
            WebRequest GetJsonApiFeedback;

            // Makes GET request
            GetJsonApiFeedback = WebRequest.Create(IPGeolocationApiUrl);
            // Internalizes Stream object
            Stream ReturnedFeedBack;

            ReturnedFeedBack = GetJsonApiFeedback.GetResponse().GetResponseStream();
            // Reads the ReturnedFeedBack and stores it in ObjReader
            StreamReader objReader             = new StreamReader(ReturnedFeedBack);
            string       IpGeolocationFeedBack = objReader.ReadToEnd();
            // Deserializing Json into C# class property's
            IpGeolocationMapping ipGeolocationMapping = JsonConvert.DeserializeObject <IpGeolocationMapping>(IpGeolocationFeedBack);

            // Prints results of Resolved Ip to screen
            Messages.PromptMessage($"Here are the results for IP-Address: {IpAddress}\n");
            Messages.PromptMessage("Results: \n");
            Messages.PromptMessage($"Country: { ipGeolocationMapping.country}\n" +
                                   $"State: {ipGeolocationMapping.regionName}\n" +
                                   $"City: {ipGeolocationMapping.city}\n" +
                                   $"Zip-Code: {ipGeolocationMapping.zip}\n" +
                                   $"ISP: {ipGeolocationMapping.isp}", ConsoleColor.Magenta);
            // Formats Results so it can be layed out in a .txt file a certain way
            string ResolvedIps = String.Format("Country: {0,-20}" +
                                               "State: {1,-20}" +
                                               "City: {2,-20}" +
                                               "Zip-Code: {3,-20}" +
                                               "ISP: {4,-20}", ipGeolocationMapping.country,
                                               ipGeolocationMapping.regionName,
                                               ipGeolocationMapping.city,
                                               ipGeolocationMapping.zip,
                                               ipGeolocationMapping.isp);
            //Writes Results to file on users Desktop
            string UsersPcName = Environment.UserName;

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"C:\Users\" + UsersPcName + @"\Desktop\ResolvedIps.txt", true))
            {
                file.WriteLine($" IP Address: {ipGeolocationMapping.query} {Environment.NewLine} {ResolvedIps} {Environment.NewLine}");
            }
        }
Exemplo n.º 2
0
        internal static void CustomIpAddress(string IpAddress)
        {
            string IPGeolocationApiUrl;

            IPGeolocationApiUrl = "http://ip-api.com/json/" + IpAddress;
            WebRequest GetJsonApiFeedback;

            GetJsonApiFeedback = WebRequest.Create(IPGeolocationApiUrl);
            Stream ReturnedFeedBack;

            ReturnedFeedBack = GetJsonApiFeedback.GetResponse().GetResponseStream();
            StreamReader         objReader             = new StreamReader(ReturnedFeedBack);
            string               IpGeolocationFeedBack = objReader.ReadToEnd();
            IpGeolocationMapping ipGeolocationMapping  = JsonConvert.DeserializeObject <IpGeolocationMapping>(IpGeolocationFeedBack);

            Messages.PromptMessage($"Here are the results for IP-Address:{IpAddress}\n");
            Messages.PromptMessage("Results: \n");
            Messages.PromptMessage($"Country: { ipGeolocationMapping.country}\n" +
                                   $"State: {ipGeolocationMapping.regionName}\n" +
                                   $"City: {ipGeolocationMapping.city}\n" +
                                   $"Zip-Code: {ipGeolocationMapping.zip}\n" +
                                   $"ISP: {ipGeolocationMapping.isp}", ConsoleColor.Magenta);

            string ResolvedIps = String.Format("Country: {0,-20}" +
                                               "State: {1,-20}" +
                                               "City: {2,-20}" +
                                               "Zip-Code: {3,-20}" +
                                               "ISP: {4,-20}", ipGeolocationMapping.country,
                                               ipGeolocationMapping.regionName,
                                               ipGeolocationMapping.city,
                                               ipGeolocationMapping.zip,
                                               ipGeolocationMapping.isp);

            string UsersPcName = Environment.UserName;

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@"C:\Users\" + UsersPcName + @"\Desktop\ResolvedIps.txt", true))
            {
                file.WriteLine($"{ResolvedIps}\n");
            }
        }