IP地址是用来做什么呢?
IP不固定,如果是拨号上网的话,可以调用RAS函数获取拨号的IP地址。如果没什么特别的用处,可以试试 127.0.0.1

解决方案 »

  1.   

    给你一个小程序:
    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;
      

  2.   

    FastNet面板里面的控件都有localip属性
    你随便拖一个下来试一试
      

  3.   

    uses
      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;
      

  4.   

    上面的朋友误会我的意思了,当上网时,不是动态给分配一个ip地址吗
    我想知道怎么获得分配给我的ip地址,不是局域网的ip地址。************
    * 努力学习 *
    *   全为   *
    *¥人民币¥*
    ************
      

  5.   

    uses
      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;
      

  6.   

    进入到  C:\_命令提示符  状态下,敲这条指令就可以了。
    ping 你的机器名  e.g.
    ping yangyugw
      

  7.   

    怎么都是局域网的地址呀,有没有能够获得
    计算机在internet上的ip地址呀************
    * 努力学习 *
    *   全为   *
    *¥人民币¥*
    ************
      

  8.   

    unit Unit1;interfaceuses
      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.
      

  9.   

    dos下用ipconfig -alldelphi中使用 nmudp控件实现
      

  10.   

    现在QQ就可以啊
    去珊瑚虫工作室看看http://www.soff.net/