首页 > Windows开发 > 详细

Delphi获取公网IP地址函数

时间:2018-03-04 11:36:15      阅读:407      评论:0      收藏:0      [点我收藏+]
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地址函数

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!