Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using RestSharp;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Drawing;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows.Forms;
  12. using Newtonsoft.Json;
  13.  
  14. namespace Lookup
  15. {
  16.     public partial class Form1 : Form
  17.     {
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void label1_Click(object sender, EventArgs e)
  24.         {
  25.         }
  26.  
  27.         private void textBox1_TextChanged(object sender, EventArgs e)
  28.         {
  29.  
  30.         }
  31.  
  32.         private void button1_Click(object sender, EventArgs e)
  33.         {
  34.  
  35.             if (textBox1.Text.Equals("") == false)
  36.             {
  37.                 textBox2.Text = FetchCurrentIpLocation(textBox1.Text);
  38.             }
  39.         }
  40.  
  41.         private string FetchCurrentIpLocation(string strIP)
  42.         {
  43.             string strIpLocation = string.Empty;
  44.  
  45.             var client = new RestClient("https://ipapi.co/"+strIP+"json/");
  46.             var request = new RestRequest()
  47.             {
  48.                 Method = Method.GET
  49.             };
  50.  
  51.             var response = client.Execute(request);
  52.  
  53.             var dictionary = JsonConvert.DeserializeObject<IDictionary>(response.Content);
  54.             foreach (var key in dictionary.Keys)
  55.             {
  56.                 strIpLocation += key.ToString() + ": " + dictionary[key] + "\r\n";
  57.             }
  58.             return strIpLocation;
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement