Delphi获取公网IP地址函数

2021-02-11 10:16

阅读:502

标签:delphi   and   asp   art   cep   ip地址   finally   url   creat   

uses IdHTTP;
function GetPublicIP: string;
var
strIP, URL: string;
iStart, iEnd: Integer;
MyIdHTTP: TIdHTTP;
begin
Result := ‘‘;
MyIdHTTP := TIdHTTP.Create(nil);
try
try
URL := MyIdHTTP.Get(http://www.ip138.com/ip2city.asp);
except
end;
finally
MyIdHTTP.Free;
end;

if Length(URL)  0 then
begin
iStart := Pos([, URL);
iEnd := Pos(], URL);
if (iStart  0) and (iEnd  0) then
begin
strIP := Trim(Copy(URL, iStart + 1, iEnd - iStart - 1));
if strIP  ‘‘ then
Result := strIP;
end;
end;
end;
获取公网IP地址函数,需要引用IdHTTP.

 

Delphi获取公网IP地址函数

标签:delphi   and   asp   art   cep   ip地址   finally   url   creat   

原文地址:https://www.cnblogs.com/westsoft/p/8503810.html


评论


亲,登录后才可以留言!