您的位置:首页 > 编程语言 > Delphi

Delphi获取公网IP地址函数

2011-07-23 21:39 288 查看
1 uses IdHTTP;
2 function GetPublicIP: string;
3 var
4 strIP, URL: string;
5 iStart, iEnd: Integer;
6 MyIdHTTP: TIdHTTP;
7 begin
8 Result := '';
9 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: