怎样通Delphi编程得到ADSL中的pppop提供的动态的IP地址?
解决方案 »
- 急了.高分求教treeviewer和数据库的连接
- delphi+SQL server2000中,如何实现这样子的批量增加!?
- 开发USB HID设备的烦恼(100分求救)
- 各位大哥,请帮我看看这个问题,谢谢!主管逼我啊!
- 正在开发或准备开发报表控件的朋友,请到这里来一起切磋切磋,QQ群:6030791
- delphi8编译Vcl Form application出错?
- 请lijinghe1(副乡长)和 knife_s(人生常恨水常东)进来接分!
- 有两个按钮,caption属性分别为“预览报表”和“打印报表”,把它们的OnClick属性设置为同一个,然后怎么判断按的是哪个按钮呢?
- 在Delphi 7 中 ClientSocket 和ServerSocket 那里去了
- 电子商务
- 如何让基于DirectShow开发的播放器能播放CD格式的文件呢?
- 怎样访问自己网站中的数据库?并能同步更新。
wsad:WSADATA;
host:PHostent;
a:Array[0..125] of Char;
ip:String;
begin
WSAStartup(MAKEWORD(1,0),wsad);
gethostname(a,125);
host:=gethostbyname(a);
ip:=IntToStr(Byte((host^.h_addr_list^+4)^));
ip:=ip+'.'+IntToStr(Byte((host^.h_addr_list^+5)^));
ip:=ip+'.'+IntToStr(Byte((host^.h_addr_list^+6)^));
ip:=ip+'.'+IntToStr(Byte((host^.h_addr_list^+7)^));
WSACleanup;
ShowMessage(ip);
end;
Function GetLocalIp(InternetIP:boolean):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;
IP: String;
begin
Screen.Cursor := crHourGlass;
try
WSAStartup($101, GInitData);
IP:='0.0.0.0';
GetHostName(Buffer, SizeOf(Buffer));
phe := GetHostByName(buffer);
if phe = nil then
begin
ShowMessage(IP);
Result:=IP;
Exit;
end;
pPtr := PaPInAddr(phe^.h_addr_list);
if InternetIP then
begin
I := 0;
while pPtr^[I] <> nil do
begin
IP := inet_ntoa(pptr^[I]^);
Inc(I);
end;
end
else
IP := inet_ntoa(pptr^[0]^);
WSACleanup;
Result:=IP;//如果上网则为上网ip否则是网卡ip
finally
Screen.Cursor := crDefault;
end;
end;//别忘记use winsock
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 IP
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;
//r:boolean;
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;
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,4,255)));
end;end.
-----------------------------------------------在Delphi里要用TWSADATA类的。