同上,谢了

解决方案 »

  1.   

    下面的过程可以列举你机器的所有IP地址,当然也包括Lan和Internet,使用方法: 
    用语句Memo1.Lines.Add('本机IP地址:'+LocalIP);就可以 
    //返回本机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 
          if i=0 
          then result:=StrPas(inet_ntoa(pptr^[I]^)) 
          else result:=result+','+StrPas(inet_ntoa(pptr^[I]^)); 
          Inc(I); 
        end; 
        WSACleanup; 
    end; 
      

  2.   

    unit Net;interfaceusesSysUtils,Windows,dialogs,winsock,Classes,ComObj,WinInet;//得到本机的局域网Ip地址Function GetLocalIp(var LocalIp:string): Boolean;//通过Ip返回机器名Function GetNameByIPAddr(IPAddr: string; var MacName: string): Boolean ;//获取网络中SQLServer列表Function GetSQLServerList(var List: Tstringlist): Boolean;//获取网络中的所有网络类型Function GetNetList(var List: Tstringlist): Boolean;//获取网络中的工作组Function GetGroupList(var List: TStringList): Boolean;//获取工作组中所有计算机Function GetUsers(GroupName: string; var List: TStringList): Boolean;//获取网络中的资源Function GetUserResource(IpAddr: string; var List: TStringList): Boolean;//映射网络驱动器Function NetAddConnection(NetPath: Pchar; PassWord: Pchar;LocalPath: Pchar): Boolean;//检测网络状态Function CheckNet(IpAddr:string): Boolean;//检测机器是否登入网络Function CheckMacAttachNet: Boolean;//判断Ip协议有没有安装 这个函数有问题Function IsIPInstalled : boolean;//检测机器是否上网Function InternetConnected: Boolean;
      

  3.   

    在delphi中有一个组件名称为:indymisc
    中的一个Ipwatch中的属性:LocalIp
    就可以直接获得本机的Ip地址
      

  4.   

    function GetLocalIP:string;
    VAR
      ch : ARRAY[1..32] OF Char;
      i : Integer;
      WSData: TWSAData;
      MyHost: PHostEnt;
      ip :string;
    begin
      ip :='';
      IF WSAstartup(2,wsdata)<>0 THEN
        BEGIN
          application.MessageBox(pchar('不能打开 Winsock: 错误 '+inttostr(WSAGetLastError)),'操作信息',mb_ok+mb_iconinformation);
          Halt(2);
        END;
      try
        IF getHostName(@ch[1],32)<>0 THEN
          BEGIN
            application.MessageBox(pchar('得到IP失败'),'操作信息',mb_ok+mb_iconinformation);
            Halt(3);
          END;
      except
        application.MessageBox(pchar('得到IP失败'),'操作信息',mb_ok+mb_iconinformation);
        halt(3);
      end;
      MyHost:=GetHostByName(@ch[1]);
      IF MyHost=NIL THEN
        BEGIN
          Halt(4);
        END
      ELSE
        BEGIN
             FOR i:=1 TO 4 DO
                BEGIN
                  ip :=ip+inttostr(ord(myhost.h_addr^[i-1]));
                  IF i<4 THEN
                     ip :=ip+'.';
                END;
       END;
       result :=ip;
    end;