请问用vb如何获取Windows当前远程登录用户的ip地址?
即其网关出口ip.举个例子:
比如A局域网对外的公网IP为202.196.22.11,
该局域网内的某台电脑通过上述网关IP连接到internet,
并用远程桌面或CITRIX等软件
登录到B局域网内的某台电脑CC,
在该CC电脑如何用vb开发一个程序来取得A局域网的对外公网IP??万分感谢,解决马上分奉上

解决方案 »

  1.   

    远程连接是3389  判断这个端口IP用winsock可以做到
      

  2.   

    本机开放的端口 Winsock1.Listen
      

  3.   

    Private Type WTS_CLIENT_ADDRESS
      ADDRESSFAMILY As Long
      ' Address family. This member can be AF_INET, AF_IPX, AF_NETBIOS, or
    AF_UNSPEC
      ADDRESS(20) As Byte
      ' Client network address
    End TypePrivate Enum WTS_INFO_CLASS
      WTSInitialProgram
      WTSApplicationName
      WTSWorkingDirectory
      WTSOEMId
      WTSSessionId
      WtsUserName
      WTSWinStationName
      WTSDomainName
      WTSConnectState
      WTSClientBuildNumber
      WTSClientName
      WTSClientDirectory
      WTSClientProductId
      WTSClientHardwareId
      WtsClientAddress
      WTSClientDisplay
      WTSClientProtocolType
    End EnumPrivate Const WTS_CURRENT_SERVER = 0&
    Private Const WTS_CURRENT_SERVER_HANDLE = 0&Private Declare Function WTSQuerySessionInformation Lib "wtsapi32" _
        Alias "WTSQuerySessionInformationW" (ByVal hServer As Long, _
        ByVal SessionID As Long, ByVal wtsInfoClass As WTS_INFO_CLASS, _
        ByRef ppBuffer As Long, ByRef pBytesReturned As Long) As LongPrivate Declare Sub WTSFreeMemory Lib "wtsapi32" ( _
        ByVal pMemory As Long)Private Declare Sub RtlMoveMemory Lib "kernel32" ( _
        pTo As Any, ByVal uFrom As Any, ByVal lSize As Long)Public Function Ptr_PtrToString(ByVal lpStr As Long, _
     ByVal lStrLen As Long) As String
      Dim sBuffer As String
      ' Fill buffer with null characters
      sBuffer = String(lStrLen, Chr(0))
      RtlMoveMemory ByVal sBuffer, ByVal lpStr, ByVal Len(sBuffer)
      Ptr_PtrToString = Replace(sBuffer, Chr(0), "")
    End FunctionPublic function IpAddress(ByVal SessionID As Long) As String
      Dim lRet As Long
      Dim wca_Tmp As WTS_CLIENT_ADDRESS
      Dim pBytesReturned As Long
      Dim ppBuffer As Long
      lRet = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, _
          SessionID, WtsClientAddress, ppBuffer, pBytesReturned)
      IpAddress = ""
      If lRet Then
        RtlMoveMemory wca_Tmp, ppBuffer, pBytesReturned
        WTSFreeMemory ppBuffer
        IpAddress = Join(Array(wca_Tmp.ADDRESS(2), wca_Tmp.ADDRESS(3), _
            wca_Tmp.ADDRESS(4), wca_Tmp.ADDRESS(5)), ".")
      End If
    End Property
      

  4.   

    CSDN藏龙卧虎,怎么可能每人帮忙呢?
    我来解决你的问题。以下是代码。
    -------------------------
    Option ExplicitPrivate Const WTS_CURRENT_SERVER_HANDLE = 0&Private WTS_CURRENT_SESSION As LongPrivate Type WTS_CLIENT_ADDRESS
         AddressFamily As Long
         Address(20) As Byte
    End TypePrivate Declare Function WTSQuerySessionInformation _
        Lib "wtsapi32" Alias "WTSQuerySessionInformationW" ( _
        ByVal hServer As Long, _
        ByVal SessionID As Long, _
        ByVal WTSInfoClass As Long, _
        ByRef Address As Long, _
        ByRef pBytesReturned As Long _
    ) As LongEnum WTSInfoClass
      WTSInitialProgram
      WTSApplicationName
      WTSWorkingDirectory
      WTSOEMId
      WTSSessionId
      WTSUserName
      WTSWinStationName
      WTSDomainName
      WTSConnectState
      WTSClientBuildNumber
      WTSClientName
      WTSClientDirectory
      WTSClientProductId
      WTSClientHardwareId
      WTSClientAddress
      WTSClientDisplay
      WTSClientProtocolType
    End EnumPrivate Declare Sub WTSFreeMemory Lib "wtsapi32.dll" (ByVal pMemory As Long)
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)
    Private Declare Function GetCurrentProcessId Lib "Kernel32.dll" () As Long
    Private Declare Sub ProcessIdToSessionId Lib "Kernel32.dll" (ByVal lngPID As Long, ByRef lngSID As Long)Private lngPID As Long
    Public Function GetClientIPAddress() As String
        Dim RetVal As Long
        Dim TmpAddress As WTS_CLIENT_ADDRESS
        Dim ByteRet As Long
        Dim lpBuffer As Long
        Dim p As Long
         
         
        ' get the id of current process running
        lngPID = GetCurrentProcessId
         
        ' get the session id in which this process is running
        ProcessIdToSessionId lngPID, WTS_CURRENT_SESSION
         
        ' user the current server, session id to trap the other details
        RetVal = WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, WTS_CURRENT_SESSION, WTSClientAddress, lpBuffer, ByteRet)
         
         
        If RetVal Then
            ' WTSQuerySessionInfo was successful.
            p = lpBuffer
             
            CopyMemory TmpAddress, ByVal p, ByteRet
             
            ' Free the memory buffer.
            WTSFreeMemory lpBuffer
        Else
            GetClientIPAddress = ""
            Err.Raise Err.Number, Err.Source, "Error with the wtsQuerySessionInfo command " & Err.LastDllError
        End If
         
        GetClientIPAddress = Trim(TmpAddress.Address(2) & "." & TmpAddress.Address(3) & "." & TmpAddress.Address(4) & "." & TmpAddress.Address(5))
         
    End Function
    Private Sub Command1_Click()
    MsgBox GetClientIPAddress()
    End Sub
      

  5.   

    楼上的xd,您这个例子得到的是本机内网的ip阿
      

  6.   

    楼上不懂不要乱叫。
    我的例子都是经过测试的,绝对可以。实现过程:
    1/A机器的IP是192.168.88.88
    2/B机器的IP是202.196.22.11A机器通过Remote Desktop连接到B机器上后,用上面的代码在B机器上执行,将会得到A机器的IP,即是192.168.88.88。
      

  7.   

    楼上我可能没表达清楚,
    我要的是A机器出口网关的公网ip地址,而不是A机器内网的ip地址
    具体看顶楼