本文整理自网络,侵删。
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.
相关阅读 >>
decodedatetime:将一个tdatetime变量拆分成它的日期/时间 部分
Delphi 捕捉异常 try except语句 和 try finally语句用法以及区别
更多相关阅读请进入《Delphi》频道 >>