topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday April 18, 2024, 6:21 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Feature Request: IP Info for URL Snooper  (Read 6466 times)

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Feature Request: IP Info for URL Snooper
« on: August 12, 2018, 03:49 PM »
Feature Request: IP Info for URL Snooper

If you have time to implement in the Context Menu of URLs a "Show IP Info" resulting in a tiny Window showing some lines of text, that would be nice.
http://ip-api.com offers a free web-api to fullfill such request. One of many, theres api-documention that explain all.

I could provide working Delphi Code if it helps to see what i miss.
If you do not like that idea it is okay aswell.

Thanks in advance. :Thmbsup:

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Feature Request: IP Info for URL Snooper
« Reply #1 on: August 12, 2018, 05:01 PM »
Here is some Demo Code to show you what i like to have as a result. I commented things a bit to understand what i do.
Code: Delphi [Select]
  1. uses WinInet;
  2.  
  3. // here i define a record to hold information
  4. type
  5.   ApiResults = record
  6.     Status: UTF8String;
  7.     Country: UTF8String;
  8.     CountryCode: UTF8String;
  9.     RegionState: UTF8String;
  10.     RegionName: UTF8String;
  11.     City: UTF8String;
  12.     Zip: UTF8String;
  13.     Latitude: UTF8String;
  14.     Longitude: UTF8String;
  15.     CityTimeZone: UTF8String;
  16.     ISP: UTF8String;
  17.     Organization: UTF8String;
  18.     NumberName: UTF8String;
  19.     DNS: UTF8String;
  20.     MobileConnection: UTF8String;
  21.     ProxyConnection: UTF8String;
  22.     QueryIP: UTF8String;
  23.     ErrorMessage: UTF8String;
  24.   end;
  25.  
  26. // this is an api function call to perform GET, optimized to handle ASCII or UNICODE data
  27. function GetUrlContentData(const Url: string): UTF8String;
  28. var
  29.   NetHandle: HINTERNET;
  30.   UrlHandle: HINTERNET;
  31.   Buffer: array[0..1023] of byte;
  32.   BytesRead: dWord;
  33.   StrBuffer: UTF8String;
  34. begin
  35.   Result := '';
  36.   NetHandle := InternetOpen('Delphi 2009', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
  37.   if Assigned(NetHandle) then
  38.     try
  39.       UrlHandle := InternetOpenUrl(NetHandle, PChar(Url), nil, 0, INTERNET_FLAG_RELOAD, 0);
  40.       if Assigned(UrlHandle) then
  41.         try
  42.           repeat
  43.             InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
  44.             SetString(StrBuffer, PAnsiChar(@Buffer[0]), BytesRead);
  45.             Result := Result + StrBuffer;
  46.           until BytesRead = 0;
  47.         finally
  48.           InternetCloseHandle(UrlHandle);
  49.         end
  50.       else
  51.         raise Exception.CreateFmt('Cannot open URL %s', [Url]);
  52.     finally
  53.       InternetCloseHandle(NetHandle);
  54.     end
  55.   else
  56.     raise Exception.Create('Unable to initialize Wininet');
  57. end;
  58.  
  59. // in here the main work is done, input will be splitted up to prior defined fields of record
  60. function GetUrlContent(const Url: string): ApiResults;
  61. var
  62.   tmp: UTF8String;
  63.   sl: TStrings;
  64. begin
  65. // api offers XML and other stuff, but LINE needs no anything, just a stringlist :)
  66. // by manual calling desired fields you get more informations, so i add them all in here
  67.   tmp := GetUrlContentData(Url+'?fields=status,country,countryCode,region,regionName,city,zip,lat,lon,timezone,isp,org,as,reverse,mobile,proxy,query,message');
  68. // the field "reverse" aka DNS-resolver consumes most of inet time, you may add option on/off for this feature
  69.   try
  70.     sl := TStringList.Create;
  71.     sl.Text := tmp;
  72. // by reading api i figured out how results could be
  73. // first received line will be "status", so i add it to its proper record field
  74.     Result.Status := sl[0];
  75. // now i compare if "status" contain "fail" to set up later received lines correct
  76. // feel free to use it as template
  77.     if Pos('fail', LowerCase(Result.Status)) > 0 then
  78.       begin
  79.         Result.ErrorMessage := sl[1];
  80.         Result.QueryIP := sl[2];
  81.       end
  82.       else
  83.       begin
  84.         Result.Country := sl[1];
  85.         Result.CountryCode := sl[2];
  86.         Result.RegionState := sl[3];
  87.         Result.RegionName := sl[4];
  88.         Result.City := sl[5];
  89.         Result.Zip := sl[6];
  90.         Result.Latitude := sl[7];
  91.         Result.Longitude := sl[8];
  92.         Result.CityTimeZone := sl[9];
  93.         Result.ISP := sl[10];
  94.         Result.Organization := sl[11];
  95.         Result.NumberName := sl[12];
  96. // the field "reverse" aka DNS-resolver consumes most of inet time, you may add option on/off for this feature
  97.         Result.DNS := sl[13];
  98.         Result.MobileConnection := sl[14];
  99.         Result.ProxyConnection := sl[15];
  100.         Result.QueryIP := sl[16];
  101.       end;
  102.   finally
  103.     sl.Free;
  104.     tmp := '';
  105.   end;
  106. end;
  107.  
  108. // here comes what GUI perform
  109. procedure TForm1.Button1Click(Sender: TObject);
  110. var
  111. // in here all results are local stored
  112.   ThisLines: ApiResults;
  113. begin
  114. // after reading api, i choosed smallest method to perform the GET and qualify results, the LINE variant
  115. // replace the second 'ip-api.com' with target IP/Domain, this is just example
  116.   ThisLines := GetUrlContent('http://ip-api.com/line/' + 'ip-api.com');
  117. // Memo1 is a Delphi Control to draw text
  118.   Memo1.Lines.Add('Status: '+ThisLines.Status);
  119. // determine what record type we have, "fail" or "success"
  120.   if Pos('fail', LowerCase(ThisLines.Status)) > 0 then
  121.    begin
  122.      Memo1.Lines.Add('ErrorMessage: '+ThisLines.ErrorMessage);
  123.      Memo1.Lines.Add('QueryIP: '+ThisLines.QueryIP);
  124.    end
  125.    else
  126.    begin
  127.      Memo1.Lines.Add('Country: '+ThisLines.Country);
  128.      Memo1.Lines.Add('CountryCode: '+ThisLines.CountryCode);
  129.      Memo1.Lines.Add('RegionState: '+ThisLines.RegionState);
  130.      Memo1.Lines.Add('RegionName: '+ThisLines.RegionName);
  131.      Memo1.Lines.Add('City: '+ThisLines.City);
  132.      Memo1.Lines.Add('Zip: '+ThisLines.Zip);
  133.      Memo1.Lines.Add('Latitude: '+ThisLines.Latitude);
  134.      Memo1.Lines.Add('Longitude: '+ThisLines.Longitude);
  135.      Memo1.Lines.Add('CityTimeZone: '+ThisLines.CityTimeZone);
  136.      Memo1.Lines.Add('ISP: '+ThisLines.ISP);
  137.      Memo1.Lines.Add('Organization: '+ThisLines.Organization);
  138.      Memo1.Lines.Add('NumberName: '+ThisLines.NumberName);
  139.      Memo1.Lines.Add('DNS: '+ThisLines.DNS);
  140.      Memo1.Lines.Add('MobileConnection: '+ThisLines.MobileConnection);
  141.      Memo1.Lines.Add('ProxyConnection: '+ThisLines.ProxyConnection);
  142.      Memo1.Lines.Add('QueryIP: '+ThisLines.QueryIP);
  143.    end;
  144. end;
« Last Edit: August 12, 2018, 06:30 PM by KodeZwerg »

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Feature Request: IP Info for URL Snooper
« Reply #2 on: August 27, 2018, 09:50 AM »
*push up in hope of any answer*

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,900
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: Feature Request: IP Info for URL Snooper
« Reply #3 on: August 27, 2018, 02:35 PM »
Seems like it would be pretty easy to do.. I could add it.. I wonder if it would be better to have it show the info in a pop up, or have a right-click context menu item to open a web page for the ip address at a site like http://ip-api.com?  Thoughts?

KodeZwerg

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 718
    • View Profile
    • Donate to Member
Re: Feature Request: IP Info for URL Snooper
« Reply #4 on: August 27, 2018, 04:54 PM »
In my own creations i pop up a Window wich just have one EditBox (readonly/to Copy things to Clipboard) inside, for myself i prefer it that way instead of loading any Huge WebBrowser.

But hey, why not SubMenu to offer both?  Just my little opinion. For myself, i would use the editbox popup.

Thanks in advance!


edit
Or a Two-In-One Thing, get Info from site, if Status = "false" offer to open in browser else popup Window?
« Last Edit: August 28, 2018, 10:28 AM by KodeZwerg »