本文整理自网络,侵删。
unit Unit1;
interface
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}uses IdHTTP, IdStack;
function GetExternalIP(UrlIpAddress:string): string;var lHTTP : TIdHTTP; lStream: TStringStream;begin lHTTP := TIdHTTP.Create(nil); lStream := TStringStream.Create(Result); try try lHTTP.Get(UrlIpAddress, lStream); lStream.Seek(0,0); Result := lStream.ReadString(lStream.Size); except Result:=''; end; finally FreeAndNil(lHTTP); FreeAndNil(lStream); end;end;
procedure TForm1.Button1Click(Sender: TObject);beginedit1.Text:=GetExternalIP('http://ip.hao828.com/ip.asp');
end;
end.
相关阅读 >>
Delphi中 tstringlist和thashedstringlist的性能对比
Delphi动态创建tadoquery加access出现'不正常的定义参数对象 提供了不一致或不完整的信息'错误
Delphi webbrowser ie 窗口选择中,选中的文字内容
更多相关阅读请进入《Delphi》频道 >>