delphi6中如何得到本机IP地址~~~???在先等!

解决方案 »

  1.   

    哥们,这样
    function GetLocalIP(var LocalIp: string): Boolean;
    var
        HostEnt: PHostEnt;
        Ip: string;
        addr: pchar;
        Buffer: array [0..63] of char;
        GInitData: TWSADATA;
    begin
      Result := False;
      try
        WSAStartup(2, GInitData);
        GetHostName(Buffer, SizeOf(Buffer));
        HostEnt := GetHostByName(buffer);
        if HostEnt = nil then Exit;
        addr := HostEnt^.h_addr_list^;
        ip := Format('%d.%d.%d.%d', [byte(addr [0]),
              byte (addr [1]), byte (addr [2]), byte (addr [3])]);
        LocalIp := Ip;
        Result := True;
      finally
        WSACleanup;
      end;
    end;
      

  2.   

    VB 有一个控件可以直接得到
     "WINSOCK"
      

  3.   

    PHostEnt,是什么啊?我这不能运行阿~谢谢
      

  4.   

    uses winsock;var
      strIP:string;
    begin
      if GetLocalIP(strIP) then
      Caption:=strip;
    end;
      

  5.   

    GetLocalIP什么意思啊?我不能运行阿
      

  6.   

    GetLocalIP 就是 hgf_hb(酸书生)  写的那个函数
    我写的是调用这个函数的方法
      

  7.   

    uses winsock;var
      strIP:string;
    begin
      if GetLocalAddress(strIP) then
      Caption:=strip;
    end;说明:
    Declaration
    function GetLocalAddress: String;Description
    The GetLocalAddress method will return the local IP address formatted for sending to an FTP server when initiating a data transfer.