delphi 获取公网IP地址


获取公网ip
uses msxml, RegularExpressions;

function GetPublicIP:string;
var
  req: IXMLHTTPRequest;
begin
  req := CoXMLHTTP.Create;
  req.open('get', 'http://city.ip138.com/ip2city.asp', False, EmptyStr, EmptyStr);
  req.send('');
  Result := TRegEx.Match(req.responseText, '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}').Value;  
end;


获取本地ip
uses IdIPWatch;

function GetNativeIP: String;
var
  IdIPWatch: TIdIPWatch;
begin
  IdIPWatch := TIdIPWatch.Create(nil);
  try
    Result := IdIPWatch.LocalIP;
  finally
    IdIPWatch.Free;
  end;
end;

联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678