IP地址是用来做什么呢?
IP不固定,如果是拨号上网的话,可以调用RAS函数获取拨号的IP地址。如果没什么特别的用处,可以试试 127.0.0.1
IP不固定,如果是拨号上网的话,可以调用RAS函数获取拨号的IP地址。如果没什么特别的用处,可以试试 127.0.0.1
解决方案 »
- 期待一份长期稳定的工作...
- 问一个我也不知道怎么说的问题
- 如何判断stringgrid中是否存在重复值?
- delphi根据数据库记录生成准考证以及打印的问题
- 我晕。AdoQuery查询出错:Cannot perform this operation on a closed dataset;
- ADO访问DBF的时候为什么如果dbf中如果有个字段是日期时间(time)型的就会访问出错!
- sql server 的SA用户密码的问题?
- 怎样使两个grid相关联呢?
- 各位兄弟,你们说网管总监视我们,我们因该怎么办
- delphi中使用ole如何判断excel的行或行中的单元格是隐藏状态
- 一个小问题,一个人学delphi,真难
- 一对主细表,删掉主表一条记录,怎么自动删掉从表的相关记录呀,不要用触发器,不用直接运行sql
Function NameToIP( Const Name : String ) : String;
Var
WSAdata : TWSAData;
HostName : Array [ 0.. 255 ] Of Char;
HostEnt : PHostEnt;
Addr : PChar;
Begin
WSAStartup( $0101, WSAdata );
Try
StrPCopy( HostName, Name );
HostEnt := GetHostByName( HostName );
If Assigned( HostEnt ) Then
Begin
If Assigned( HostEnt^.h_addr_list ) Then
Begin
Addr := hostEnt^.h_addr_list^;
If Assigned( Addr ) Then Result := Format( '%d.%d.%d.%d', [ Byte( Addr[ 0 ] ),Byte( Addr[ 1 ] ),Byte(Addr[ 2 ] ),Byte(Addr[ 3 ] ) ] )
Else Result := '';
End
Else Result := '';
End
Else Result := '';
Finally
WSACleanup;
End;
End;
你随便拖一个下来试一试
WinSock;procedure TForm1.Button1Click(Sender: TObject);
var
ComputerName: array[0..32] of char;
w: Cardinal;
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
GetComputerName(ComputerName, w);
if WSAStartup(MakeWord(2, 0), WSAData) = 0 then
begin
HostEnt := GetHostByName(ComputerName);
if HostEnt <> nil then
ShowMessage(inet_ntoa(PInAddr(HostEnt^.h_Addr^)^));
WSACleanup;
end;
end;
我想知道怎么获得分配给我的ip地址,不是局域网的ip地址。************
* 努力学习 *
* 全为 *
*¥人民币¥*
************
WinSock;
Function Tform1.GetIp: String;
Var
aa: pchar;
hostaddr: phostent;
i: integer;
bb: wsadata;
Begin
GetMem(aa, 80);
FillChar(aa^, 80, 0);
WSAStartup(2, bb);
If gethostname(aa, 80) <> SOCKET_ERROR Then
Begin
hostaddr := gethostbyname(aa);
For i := 0 To hostAddr^.h_length - 1 Do
Begin
Result := Result + '.' + IntToStr(ord(HostAddr^.H_addr_List^[i]));
End;
delete(result, 1, 1);
FreeMem(aa);
End;
End;
ping 你的机器名 e.g.
ping yangyugw
计算机在internet上的ip地址呀************
* 努力学习 *
* 全为 *
*¥人民币¥*
************
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Menus,WinSock, ExtCtrls,ClipBrd;type
TForm1 = class(TForm)
StaticText1: TStaticText;
PopupMenu1: TPopupMenu;
N1: TMenuItem;
N2: TMenuItem;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure N1Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N1StartDrag(Sender: TObject;var DragObject: TDragObject);
procedure StaticText1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
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;procedure TForm1.FormCreate(Sender: TObject);
var
FullRgn,ClientRgn,ButtonRgn:Thandle;
Margin,x,y:integer;
begin
Top:=0;
Left:=Screen.Width-StaticText1.Width ;
Height:=StaticText1.Height;
Width:=StaticText1.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+StaticText1.Left;
y:=Y+StaticText1.Top;
ButtonRgn:=CreateRectRgn(x,y,x+StaticText1.Width,y+StaticText1.Height);
CombineRgn(FullRgn,FullRgn,ButtonRgn,RGN_OR);
SetWindowRgn(Handle,FullRGN,True);
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);
SetWindowPos(handle,HWND_TOPMOST,Form1.Left,Form1.Top,Form1.Width,Form1.Height,SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE or SWP_NOMOVE);
end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
Timer1.Interval:=1000*100;
StaticText1.Caption:='IP:'+LocalIP+#13#10+'HostName:'+HostName;
end;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.N1Click(Sender: TObject);
begin
Application.Terminate;
end;procedure TForm1.N2Click(Sender: TObject);
begin
Clipboard.SetTextBuf(pchar(copy(StaticText1.Caption,0,255)));
end;procedure TForm1.N1StartDrag(Sender: TObject;
var DragObject: TDragObject);const
sc_dragmove = $f012;
begin
releasecapture;
twincontrol(application.mainform).perform(wm_syscommand,sc_dragmove, 0);end;
procedure TForm1.StaticText1MouseDown(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;end.
去珊瑚虫工作室看看http://www.soff.net/