如何取得本机在Internet上的动态IP地址? 如何取得本机在Internet上的动态IP地址?分不够再加! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用Indy Misc里的TIdIpWatch来做 unit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Winsock, StdCtrls, ExtCtrls, Menus ,clipbrd;type TForm1 = class(TForm) Timer1: TTimer; PopupMenu1: TPopupMenu; Exit1: TMenuItem; Label1: TLabel; Copy1: TMenuItem; procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Exit1Click(Sender: TObject); procedure formmousedown(sender: tobject; button: tmousebutton; shift: tshiftstate; x, y: integer); procedure Edit1StartDrag(Sender: TObject; var DragObject: TDragObject); procedure Copy1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}// returns ISP assigned IPfunction HostName : string;var Buffer : array [0..63] of char; GInitData : TWSADATA;begin WSAStartup($101, GInitData); Result := ''; GetHostName(Buffer, SizeOf(Buffer)); Result := StrPas(Buffer); WSACleanup;end;function LocalIP : string;type TaPInAddr = array [0..10] of PInAddr; PaPInAddr = ^TaPInAddr;var phe : PHostEnt; pptr : PaPInAddr; Buffer : array [0..63] of char; I : Integer; GInitData : TWSADATA;begin WSAStartup($101, GInitData); Result := ''; GetHostName(Buffer, SizeOf(Buffer)); phe :=GetHostByName(buffer); if phe = nil then Exit; pptr := PaPInAddr(Phe^.h_addr_list); I := 0; while pptr^[I] <> nil do begin result:=StrPas(inet_ntoa(pptr^[I]^)); Inc(I); end; WSACleanup;end;{subject : moving forms (and other twincontrols) without using the caption-bar}procedure tForm1.formmousedown(sender: tobject; button: tmousebutton; shift: tshiftstate; x, y: integer);const sc_dragmove = $f012;begin releasecapture; twincontrol(application.mainform).perform(wm_syscommand,sc_dragmove, 0);end;procedure TForm1.FormCreate(Sender: TObject);var FullRgn, ClientRgn, ButtonRgn: THandle; Margin, X, Y: Integer;begin top:=screen.Height-50; left:=screen.width-120; height:=Label1.Height; width:=Label1.width; Margin := (Width - ClientWidth) div 2; FullRgn := CreateRectRgn(0, 0, Width, Height); X := Margin; Y := Height - ClientHeight - Margin; ClientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight); CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF); X := X + Label1.Left; Y := Y + Label1.Top; ButtonRgn := CreateRectRgn(X, Y, X + Label1.Width, Y + Label1.Height); CombineRgn(FullRgn, FullRgn, ButtonRgn, RGN_OR); SetWindowRgn(Handle, FullRgn, True); //Hide Taskbar Icon ShowWindow( Application.Handle, SW_HIDE ); SetWindowLong( Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW); ShowWindow( Application.Handle, SW_SHOW );end;procedure TForm1.Timer1Timer(Sender: TObject);begin Timer1.interval:=1000*100; Label1.Caption:='IP: '+LocalIP + #13#10 + 'HostName: '+HostName;end;procedure TForm1.Exit1Click(Sender: TObject);begin application.terminate;end;procedure TForm1.Edit1StartDrag(Sender: TObject; var DragObject: TDragObject);const sc_dragmove = $f012;begin releasecapture; twincontrol(application.mainform).perform(wm_syscommand,sc_dragmove, 0);end;procedure TForm1.Copy1Click(Sender: TObject);begin Clipboard.SetTextBuf(Pchar(copy(Label1.caption,0,255)));end;end. 用TIdIPWatch(在Indy Misc页内)IdIPWatch1.Active:=True;ShowMessage(IdIPWatch1.LocalIP); li_zhifu(东北人): 我按照你的代码取得的只是在局域网的IP。 我想的要是在Internet网上的动态IP.(例如我是拨号上网,) 我刚才从别的帖子上找到了答案:function LocalIP1 : string;type TaPInAddr = array [0..10] of PInAddr; PaPInAddr = ^TaPInAddr;var phe : PHostEnt; pptr : PaPInAddr; Buffer : array [0..63] of char; I : Integer; GInitData : TWSADATA;begin WSAStartup($101, GInitData); Result := ''; GetHostName(Buffer, SizeOf(Buffer)); phe :=GetHostByName(buffer); if phe = nil then Exit; pptr := PaPInAddr(Phe^.h_addr_list); I := 0; while pptr^[I] <> nil do begin result:=StrPas(inet_ntoa(pptr^[I]^)); Inc(I); end; WSACleanup;end; delphi 调用DLL,出现问题,请各位看看 。。。。急急急 求教个Hook Api 的卸载问题。。。。急。。 ^M=#13 ^A=#1 ^0='p' ^1='q' ...为什么? 再问一个问题:如何在服务器中为客户建立相应的线程?? 如何定义为一个通用的过程,高分相送 有关PE文件的问题(高手请进,分不够可以再加)!! 如何去掉半个汉字等非法字符 关于保存的贴子(Xml文件)无法正常显示的解决办法。 各位老大救救我? 请教高手GetSystemInfo()的具体使用方法,我只有27分 一个截面问题 十万火急!!!! SQLServer 問題! 問題解決,立即結貼!
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Winsock, StdCtrls, ExtCtrls, Menus ,clipbrd;type
TForm1 = class(TForm)
Timer1: TTimer;
PopupMenu1: TPopupMenu;
Exit1: TMenuItem;
Label1: TLabel;
Copy1: TMenuItem;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure formmousedown(sender: tobject; button: tmousebutton;
shift: tshiftstate; x, y: integer);
procedure Edit1StartDrag(Sender: TObject; var DragObject: TDragObject);
procedure Copy1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}// returns ISP assigned IP
function HostName : string;
var
Buffer : array [0..63] of char;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
Result := StrPas(Buffer);
WSACleanup;
end;function LocalIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;{subject : moving forms (and other twincontrols) without using the caption-bar}procedure tForm1.formmousedown(sender: tobject; button: tmousebutton;
shift: tshiftstate; x, y: integer);
const
sc_dragmove = $f012;
begin
releasecapture;
twincontrol(application.mainform).perform(wm_syscommand,sc_dragmove, 0);
end;procedure TForm1.FormCreate(Sender: TObject);
var
FullRgn, ClientRgn, ButtonRgn: THandle;
Margin, X, Y: Integer;
begin
top:=screen.Height-50;
left:=screen.width-120;
height:=Label1.Height;
width:=Label1.width;
Margin := (Width - ClientWidth) div 2;
FullRgn := CreateRectRgn(0, 0, Width, Height);
X := Margin;
Y := Height - ClientHeight - Margin;
ClientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight);
CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF);
X := X + Label1.Left;
Y := Y + Label1.Top;
ButtonRgn := CreateRectRgn(X, Y, X + Label1.Width, Y + Label1.Height);
CombineRgn(FullRgn, FullRgn, ButtonRgn, RGN_OR);
SetWindowRgn(Handle, FullRgn, True);
//Hide Taskbar Icon
ShowWindow( Application.Handle, SW_HIDE );
SetWindowLong( Application.Handle, GWL_EXSTYLE,
GetWindowLong(Application.Handle, GWL_EXSTYLE) or
WS_EX_TOOLWINDOW and not WS_EX_APPWINDOW);
ShowWindow( Application.Handle, SW_SHOW );
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.interval:=1000*100;
Label1.Caption:='IP: '+LocalIP + #13#10
+ 'HostName: '+HostName;
end;procedure TForm1.Exit1Click(Sender: TObject);
begin
application.terminate;
end;procedure TForm1.Edit1StartDrag(Sender: TObject;
var DragObject: TDragObject);
const
sc_dragmove = $f012;
begin
releasecapture;
twincontrol(application.mainform).perform(wm_syscommand,sc_dragmove, 0);end;procedure TForm1.Copy1Click(Sender: TObject);
begin
Clipboard.SetTextBuf(Pchar(copy(Label1.caption,0,255)));
end;end.
IdIPWatch1.Active:=True;
ShowMessage(IdIPWatch1.LocalIP);
我按照你的代码取得的只是在局域网的IP。
我想的要是在Internet网上的动态IP.(例如我是拨号上网,)
function LocalIP1 : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;