想知道如何自动获得ADSL的动态IP。

解决方案 »

  1.   

    用TClientSocket连接服务器后,用
    ClientSocket->Socket->LocalAddress得到。
      

  2.   

    function GetLocalIPs: String;
    type PPInAddr= ^PInAddr;
    var
      wsaData: TWSAData;
      HostInfo: PHostEnt;
      HostName: Array[0..255] of Char;
      Addr: PPInAddr;
    begin
      Result:='';
      if WSAStartup($0101, wsaData)<>0 then exit;
      try
        if gethostname(HostName, SizeOf(HostName)) <> 0 then exit;
        HostInfo:= gethostbyname(HostName);
        if HostInfo=nil then Exit;
        Addr:=Pointer(HostInfo^.h_addr_list);
        if (Addr=nil) or (Addr^=nil) then exit;
        Result:=StrPas(inet_ntoa(Addr^^));
        inc(Addr);
        while Addr^<>nil do begin
          Result:=Result+^M^J+StrPas(inet_ntoa(Addr^^));
          inc(Addr);
        end;
      finally
        WSACleanup;
      end;
    end;用这个function获得IP地址,再发送出去。