uses
WinInet;
//免强可以,找个能返回IP的网址,下面138IP可以的。
function LoadServer(const SvrScript: string; var RetString: string): BOOL;
var
NetHandle: HINTERNET;
UrlHandle: HINTERNET;
Buffer: array[0..1024] of char;
BytesRead: cardinal;
begin
RetString := '';
Result := False;
//打开Internet 句柄
NetHandle := InternetOpen('Delphi 5.x', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
//是否分配成功成名遂
if Assigned(NetHandle) then
begin
//打开URL句柄
UrlHandle := InternetOpenUrl(NetHandle, PChar(SvrScript), nil, 0, INTERNET_FLAG_RELOAD, 0);
if Assigned(UrlHandle) then
begin
//打开成功, 填充数组
FillChar(Buffer, SizeOf(Buffer), 0);
repeat
//保存结果
RetString := RetString + StrPas(Buffer);
FillChar(Buffer, SizeOf(Buffer), 0);
//读取Buffer
InternetReadFile(UrlHandle, @Buffer, SizeOf(Buffer), BytesRead);
until BytesRead = 0;
//关闭URL句柄
InternetCloseHandle(UrlHandle);
Result := True;
end
else Result := False;
//关闭Intenet句柄
InternetCloseHandle(NetHandle);
end; // end if NetHandle <> 0 then
end;
procedure Tfrm_FCUDPServer.Button1Click(Sender: TObject);
const
IPPos = '您的IP地址是:';
var
IP138Server: string;
l_pos: Integer;
begin
mmo1.Clear;
if not LoadServer('http://www.ip138.com/', IP138Server) then
if not LoadServer('http://www.ip138.com/', IP138Server) then
if not LoadServer('http://www.ip138.com/', IP138Server) then
if not LoadServer('http://www.ip138.com/', IP138Server) then
if not LoadServer('http://www.ip138.com/', IP138Server) then; //注意这里不能掉了分号
if IP138Server <> '' then
begin
l_pos := Pos(IPPos, IP138Server);
if l_pos > 0 then
begin
IP138Server := Copy(IP138Server, l_pos + Length(IPPos), 15);
IP138Server := Copy(IP138Server, 1, Pos('<', IP138Server) - 1);
lbledt_NetIP.Text := IP138Server;
end;
end;
end;