一台机子拨号上网,如何获得他的临时IP地址,注意不是局域网中的IP地址?谢谢!!

解决方案 »

  1.   

    下载http://www.applevb.com/sourcecode/nettools.zip 看看
      

  2.   

    Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)Declare Function gethostbyname& Lib "wsock32.dll" (ByVal hostname$)Private Const SOCKET_ERROR = -1Type Hostent
        h_name As Long
        h_aliases As Long
        h_addrtype As Integer
        h_length As Integer
        h_addr_list As Long
    End TypeDim Hostent As Hostent, PointerToPointer As Long, ListAddress As Long
    Public Function vbGetHostByName(Optional strHostName As String = "www.csdn.net")    Dim szString As String
        Dim sMsg As String    szString = String(64, &H0)
        strHostName = strHostName + Mid(szString, Len(szString) - 64 + Len(strHostName), 64 - Len(strHostName))    If gethostbyname(strHostName) = SOCKET_ERROR Then              ' If WSock32 error, then tell me about it
            sMsg = "Winsock Error" & Str$(WSAGetLastError())
            MsgBox sMsg, vbOKOnly, "Administrator"
        Else
            PointerToPointer = gethostbyname(strHostName)              ' Get the pointer to the address of the winsock hostent structure
            CopyMemory Hostent.h_name, ByVal _
            PointerToPointer, Len(Hostent)                      ' Copy Winsock structure to the VisualBasic structure        ListAddress = Hostent.h_addr_list                   ' Get the ListAddress of the Address List
            CopyMemory ListAddr, ByVal ListAddress, 4           ' Copy Winsock structure to the VisualBasic structure
            CopyMemory IPLong, ByVal ListAddr, 4                ' Get the first list entry from the Address List
            CopyMemory Addr, ByVal ListAddr, 4        'Label3.Caption = Trim$(CStr(Asc(IPLong.Byte4)) + "." + CStr(Asc(IPLong.Byte3)) _
                + "." + CStr(Asc(IPLong.Byte2)) + "." + CStr(Asc(IPLong.Byte1)))
        End IfEnd Function
      

  3.   

    有一种作法就是用DOS命令ipconfig/all生成一个文件然后到这个文件去找。
      

  4.   

    winsock控件的localip属性就可以返回ip !