机器有多网卡,所以有多个ip地址,怎么得到所有的ip地址列表?

解决方案 »

  1.   

    按设置的ip地址,查找一下注册表。找到具体的位置。。
    然后写程序读出ip列表。
    反正一块网卡是这样的。多块就没试过。应该读注册表行的。
      

  2.   

    参见
    WSAStartup
    gethostname
    gethostbyaddr
      

  3.   

    给你个例子,我找了好久才找到,n年前协的#include "winsock.hpp"
    ......他会把结果写入Memo1里面的
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
      char szHostName[128];
      AnsiString sWideBandIP;
      WSADATA wsaData;
      AnsiString addr;  if(WSAStartup(0x202,&wsaData)!=0)
      {
        WSACleanup();
        return;
      }
      if( gethostname(szHostName, 128) != 0 )
      {
        ShowMessage(WSAGetLastError());
        return;
      }  // Get host adresses
      HOSTENT * pHost;
      int i;  pHost = gethostbyname(szHostName);  for( i = 0; pHost!= NULL && pHost->h_addr_list[i]!= NULL; i++ )
      {
          AnsiString str="";
          int j;      for( j = 0; j < pHost->h_length; j++ )
          {
            addr="";
            if( j > 0 )
              str += ".";
            str += IntToStr(((unsigned char*)pHost->h_addr_list[i])[j]);
           }
          // Display all IPs
          Memo1->Lines->Add(str);
      }
      WSACleanup();
    }
    //
      

  4.   

    down个ICS控件就有了,WInsock也可以的
    http://www.overbyte.be
    http://www.rtfm.be/fpiette/indexuk.htm
    http://users.swing.be/francois.piette/indexuk.htm
      

  5.   

    这是pascal的,前面写上user winsock;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;
      

  6.   

    这里有!
    http://overbyte.delphicenter.com/eng/download.html?url=http://overbyte.delphicenter.com/arch/icsbeta.zip
      

  7.   

    ICS中WSocket.pas 的function  LocalIPList就是了