我的机器在局域网内,我们的局域网通过ADSL连接到Internet,请问应该如何取得我的机器的对外IP呢?

解决方案 »

  1.   

    对方的服务器当然知道的
    你的本地IP经过NAT上网,对方接受到的是NAT出口IP,也就是你的InternetIP了1)访问你的ADSL或NAT路由器,获得外网IP2)通过访问外部的Web服务获得,HTTP访问Internet的Web服务,它必定知道你的IP,结果下载回来就可以了。你需要外部服务器的支持:)例如http://www.hao123.com/ss/localip.htm
    呵呵
      

  2.   

    type{ Identifies an active RAS Connection.  (See RasConnectEnum) }
          PRASConn = ^TRASConn;
          TRASConn = record
            dwSize: DWORD;
            hRasConn: HRASConn;
            szEntryName:  array[0..RAS_MaxEntryName] of Char;
            szDeviceType: array[0..RAS_MaxDeviceType] of Char;
            szDeviceName: array[0..RAS_MaxDeviceName] of char;
          end;
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          PRASConnStatus = ^TRASConnStatus;
          TRASConnStatus = record
            dwSize: LongInt;
            dwError: LongInt;
            rasConnstate: Word;
            szDeviceType: array[0..RAS_MaxDeviceType] of Char;
            szDeviceName: array[0..RAS_MaxDeviceName] of Char;
          end;
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          PRASDIALEXTENSIONS= ^TRASDIALEXTENSIONS;
          TRASDIALEXTENSIONS= record
            dwSize: DWORD;
            dwfOptions: DWORD;
            hwndParent: HWND;
            reserved: DWORD;
          end;
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          PRASDialParams = ^TRASDialParams;
          TRASDialParams = record
            dwSize: DWORD;
            szEntryName:      array[0..RAS_MaxEntryName] of Char;
            szPhoneNumber:    array[0..RAS_MaxPhoneNumber] of Char;
            szCallbackNumber: array[0..RAS_MaxCallbackNumber] of Char;
            szUsername:       array[0..UNLEN] of Char;
            szPassword:       array[0..PWLEN] of Char;
            szDomain:         array[0..DNLEN] of Char;
            end;
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          PRASEntryName = ^TRASEntryName;
          TRASEntryName = record
            dwSize: LongInt;
            szEntryName: array[0..RAS_MaxEntryName] of Char;
          { Reserved: Byte;}
          end;
          //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          TRASPPPIP = record
            dwSize: DWORD;
            dwError: DWORD;
            szlpAddress: array[0..15] of char;
          end;//==============================================================================
    //取得拨号连接的IP地址**********************************************************
    //==============================================================================
    procedure GetRasIP(var RasIP: PChar; Index: Byte = 0);
    var BufSize, Connxions, RASIPSize: DWORD;
        RASPPPIP: TRASPPPIP;
        RasConn: array[0..24] of TRasConn;
    begin
      RasConn[Index].dwSize := SizeOf(TRasConn);
      BufSize := SizeOf(TRasConn);
      if RasEnumConnections(@RasConn, BufSize, Connxions)=0 then
      begin
        RASPPPIP.dwsize := SizeOf(TRASPPPIP);
        RASIPSize := SizeOf(TRASPPPIP);
        RASGetProjectionInfo(RasConn[Index].hRasConn, $8021, RASPPPIP, RASIPSize);
        lstrcpy(RasIP, RASPPPIP.szlpAddress);
      end;
    end;
      

  3.   

    function RasDial(lpRasDialExtensions : PRASDIALEXTENSIONS ; { pointer to function extensions data }
                     lpszPhonebook: PChar;                      { pointer to full path and filename of phonebook file }
                     lpRasDialParams : PRASDIALPARAMS;          { pointer to calling parameters data }
                     dwNotifierType : DWORD;                    { specifies type of RasDial event handler }
                     lpvNotifier: DWORD;                        { specifies a handler for RasDial events }
                     var rasConn: HRASConn                      { pointer to variable to receive connection handle }
                    ): DWORD; stdcall;function RasEnumConnections(RASConn: PrasConn;              { buffer to receive Connections data }
                                var BufSize: DWord;             { size in bytes of buffer }
                                var Connections: DWord          { number of Connections written to buffer }
                               ): LongInt; stdcall;function RasEnumEntries(reserved: PChar;                    { reserved, must be NULL }
                            lpszPhonebook: PChar  ;             { pointer to full path and filename of phonebook file }
                            lprasentryname: PRASENTRYNAME ;     { buffer to receive phonebook entries }
                            var lpcb: DWORD;                    { size in bytes of buffer }
                            var lpcEntries : DWORD              { number of entries written to buffer }
                           ): DWORD; stdcall;function RasGetConnectStatus(RASConn: hrasConn;             { handle to Remote Access Connection of interest }
                                 RASConnStatus: PRASConnStatus  { buffer to receive status data }
                                ): LongInt; stdcall;function RasGetErrorString(ErrorCode: DWord;                { error code to get string for }
                               szErrorString: PChar;            { buffer to hold error string }
                               BufSize: DWord                   { sizeof buffer }
                              ): LongInt; stdcall;function RasHangUp(RASConn: hrasConn                        { handle to the Remote Access Connection to hang up }
                      ): LongInt; stdcall;function RasGetEntryDialParams(lpszPhonebook:PChar;                { pointer to the full path and filename of the phonebook file }
                                   var lprasdialparams:TRASDIALPARAMS; { pointer to a structure that receives the connection parameters }
                                   var lpfPassword : BOOL              { indicates whether the user's password was retrieved }
                                  ): DWORD; stdcall;function RASGetProjectionInfo(hRasConn: THandle;
                                  RasProjection: DWORD;
                                  var lpRasPPPIP: TRasPPPIP;
                                  var lpcb: DWORD
                                 ): DWORD; stdcall;const RASAPI32 = 'RASAPI32.DLL';function RasDial;               external RASAPI32 name 'RasDialA';
    function RasHangUp;             external RASAPI32 name 'RasHangUpA';
    function RasEnumEntries;        external RASAPI32 name 'RasEnumEntriesA';
    function RasGetErrorString;     external RASAPI32 name 'RasGetErrorStringA';
    function RasEnumConnections;    external RASAPI32 name 'RasEnumConnectionsA';
    function RasGetConnectStatus;   external RASAPI32 name 'RasGetConnectStatusA';
    function RASGetProjectionInfo;  external RASAPI32 name 'RasGetProjectionInfoA';
    function RasGetEntryDialParams; external RASAPI32 name 'RasGetEntryDialParamsA';
      

  4.   

    use winsock;
    Function Tmain_form.GetLocalIp(InternetIP:boolean):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;
        IP: String;
    begin
        Screen.Cursor := crHourGlass;
        try
          WSAStartup($101, GInitData);
          IP:='0.0.0.0';
          GetHostName(Buffer, SizeOf(Buffer));
          phe := GetHostByName(buffer);
          if phe = nil then
          begin
            ShowMessage(IP);
            Result:=IP;
            Exit;
          end;
          pPtr := PaPInAddr(phe^.h_addr_list);
          if InternetIP then
            begin
              I := 0;
              while pPtr^[I] <> nil do
                begin
                  IP := inet_ntoa(pptr^[I]^);
                  Inc(I);
                end;
            end
          else
            IP := inet_ntoa(pptr^[0]^);
          WSACleanup;
          Result:=IP;//如果上网则为上网ip否则是网卡ip
        finally
          Screen.Cursor := crDefault;
        end;
    end;
      

  5.   

    不好意思,没看清楚你的问题,对于你的问题,我想没法解决,理由是,你的机子如果是代理上去的话,本机就不存在外网的ip,也就无法获取外网ip
      

  6.   

    那个网站怎么能知道我的IP呢,是什么原理?
    -------------------------------------------
    在asp 编程里有个函数,具体忘了,你可以找找。