根据Inno Setup中的在线列表检查IP地址 [英] Check an IP address against an online list in Inno Setup

查看:55
本文介绍了根据Inno Setup中的在线列表检查IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码获取用户IP地址

I am getting the user IP address using the below code

function GetIp: string;
var
  WinHttpReq: Variant;
begin
    try
      WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
      WinHttpReq.Open('GET', 'http://ipinfo.io/ip', False);
      WinHttpReq.Send;
      Result := Trim(WinHttpReq.ResponseText);
    except
      Log(GetExceptionMessage);
      Result := '8.8.8.8';
    end;
end;

获取用户IP地址后,我需要检查我的在线JSON列表中是否已经存在该IP地址.

After getting the users IP address I need to check if that IP address already exists in my online JSON list.

谢谢

推荐答案

最简单的解决方案是下载JSON文本文件并搜索IP地址.

The simplest solution is to download your JSON text file and search your IP address.

重复使用代码以使用HTTP(或更好的HTTPS)检索文档:

Reuse your code to retrieve a document using HTTP (or better HTTPS):

function HttpGet(Url: string): string;
var
  WinHttpReq: Variant;
begin
  WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
  WinHttpReq.Open('GET', Url, False);
  WinHttpReq.Send;
  Result := Trim(WinHttpReq.ResponseText);
end;

然后您可以像这样使用它:

And then you can use it like:

var
  Ip: string;
  List: string;
begin
  try
    Ip := HttpGet('https://ipinfo.io/ip');
    List := HttpGet('https://www.example.com/publicly/available/list.json');

    if Pos('["' + Ip + '"]', List) > 0 then
    begin
      Log(Format('IP %s is in the list', [Ip]));
    end
      else
    begin
      Log(Format('IP %s is not in the list', [Ip]));
    end;
  except
    Log(Format('Error testing if IP is in the list - %s', [GetExceptionMessage]));
  end;
end;

尽管您必须将列表公开.当前,必须先登录Google才能访问您的URL.

Though you will have to make your list publicly available. Currently your URL cannot be accessed, without logging to Google first.

如果您想正确处理JSON,请参见
如何在Inno Setup中解析JSON字符串?

If you want to process your JSON properly, see
How to parse a JSON string in Inno Setup?

这篇关于根据Inno Setup中的在线列表检查IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆