通过网站获取公网IP的小程序,使用IdHTTP。(http://www.2ccc.com/article.asp?articleid=4076 这里下载的)
主要代码:
function GetLocalIP(FIdHTTP : TIdHTTP;DealType : TDealType) : string;
var
IPSTR , IPSTR1 : String;
iPos : Integer;
begin
Result := '';
Case DealType Of
GuoNei : Begin
IPSTR := FIdHTTP.Get('http://www.ip138.com') ;
iPos := Pos('您的IP地址是',IPSTR);
if iPos <> 0 then
IPSTR1 := Copy(IPSTR,iPos+12,20);
iPos := Pos(':',IPSTR1);
if iPos <> 0 Then
Result := Trim(Copy(IPSTR1,iPos+2,15));
End;
GuoWai : Begin
IPSTR := FIdHTTP.Get('http://vbnet.mvps.org/resources/tools/getpublicip.shtml');
iPos := Pos('var',IPSTR);
if iPos <> 0 Then
IPSTR1 := Trim(Copy(IPSTR,iPos+3,30));
iPos := Pos('ip',IPSTR1);
if iPos <> 0 Then
Result := Trim(Copy(IPSTR1,iPos + 6,15));
End;
End;
end;