Advertisement
Cinder1986

geoping

May 15th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. static void GeoPing(string address, ITelegramBotClient botClient, Message message)
  2. {
  3. botClient.SendTextMessageAsync(message.Chat.Id, "Checking hostname...", replyMarkup: GetReturnButton());
  4. string url = $"https://geonet.shodan.io/api/geoping/{address}";
  5. {
  6. using (HttpClient client = new HttpClient())
  7. {
  8. HttpResponseMessage response = client.GetAsync(url).Result;
  9. string jsonString = response.Content.ReadAsStringAsync().Result;
  10. if (!jsonString.Contains("Invalid hostname") && !jsonString.Contains("\"packets_sent\":0"))
  11. {
  12. var json = JsonSerializer.Deserialize<GeoPingClass[]>(jsonString);
  13. if (json != null)
  14. foreach (var item in json)
  15. {
  16. if (cancelTokenSource.Token.IsCancellationRequested)
  17. return;
  18. if (item != null && item.from_loc != null)
  19. {
  20. botClient.SendTextMessageAsync(message.Chat.Id, $"Country: {item.from_loc.country}\nCity: {item.from_loc.city}\n" + (item.is_alive ? "Available ✅" : "Not available ❌"), cancellationToken: cancelTokenSource.Token, replyMarkup: GetReturnButton());
  21. Thread.Sleep(500);
  22. }
  23. }
  24. }
  25. else
  26. {
  27. currTask = 2;
  28. botClient.SendTextMessageAsync(message.Chat.Id, "Invalid hostname!", cancellationToken: cancelTokenSource.Token, replyMarkup: GetReturnButton());
  29. return;
  30. }
  31.  
  32. }
  33. }
  34. botClient.SendTextMessageAsync(message.Chat.Id, "Completed!", cancellationToken: cancelTokenSource.Token, replyMarkup: GetButtons());
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement