|
网友lirong发的
获取计算机(本地/公网)IP地址
Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_ADAPTER_NAME_LENGTH As Long = 256
Private Const MAX_ADAPTER_DESCRIPTION_LENGTH As Long = 128
Private Const MAX_ADAPTER_ADDRESS_LENGTH As Long = 8
Private Type IP_ADDRESS_STRING
IpAddr(0 To 15) As Byte
End Type
Private Type IP_MASK_STRING
IpMask(0 To 15) As Byte
End Type
Private Type IP_ADDR_STRING
dwNext
As Long
IpAddress As IP_ADDRESS_STRING
IpMask
As IP_MASK_STRING
dwContext As Long
End Type
Private Type IP_ADAPTER_INFO
dwNext
As Long
ComboIndex
As Long
'reserved
sAdapterName(0 To (MAX_ADAPTER_NAME_LENGTH + 3))
As Byte
sDescription(0 To (MAX_ADAPTER_DESCRIPTION_LENGTH + 3)) As Byte
dwAddressLength
As Long
sIPAddress(0 To (MAX_ADAPTER_ADDRESS_LENGTH - 1))
As Byte
dwIndex
As Long
uType
As Long
uDhcpEnabled
As Long
CurrentIpAddress
As Long
IpAddressList
As IP_ADDR_STRING
GatewayList
As IP_ADDR_STRING
DhcpServer
As IP_ADDR_STRING
bHaveWins
As Long
PrimaryWinsServer
As IP_ADDR_STRING
SecondaryWinsServer
As IP_ADDR_STRING
LeaseObtained
As Long
LeaseExpires
As Long
End Type
Private Declare Function GetAdaptersInfo Lib "iphlpapi.dll" (pTcpTable As Any, _
pdwSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(dst As Any, src As Any, ByVal bcount As Long)
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Function GetPublicIP()
Dim sSourceUrl As String
Dim sLocalFile As String
Dim hfile
As Long
Dim buff
As String
Dim pos1
As Long
Dim pos2
As Long
'site returning IP address
获取计算机(本地/公网)IP地址
Private Const ERROR_SUCCESS As Long = 0
Private Const MAX_ADAPTER_NAME_LENGTH As Long = 256
Private Const MAX_ADAPTER_DESCRIPTION_LENGTH As Long = 128
Private Const MAX_ADAPTER_ADDRESS_LENGTH As Long = 8
Private Type IP_ADDRESS_STRING
IpAddr(0 To 15) As Byte
End Type
Private Type IP_MASK_STRING
IpMask(0 To 15) As Byte
End Type
Private Type IP_ADDR_STRING
dwNext
As Long
IpAddress As IP_ADDRESS_STRING
IpMask
As IP_MASK_STRING
dwContext As Long
End Type
Private Type IP_ADAPTER_INFO
dwNext
As Long
ComboIndex
As Long
'reserved
sAdapterName(0 To (MAX_ADAPTER_NAME_LENGTH + 3))
As Byte
sDescription(0 To (MAX_ADAPTER_DESCRIPTION_LENGTH + 3)) As Byte
dwAddressLength
As Long
sIPAddress(0 To (MAX_ADAPTER_ADDRESS_LENGTH - 1))
As Byte
dwIndex
As Long
uType
As Long
uDhcpEnabled
As Long
CurrentIpAddress
As Long
IpAddressList
As IP_ADDR_STRING
GatewayList
As IP_ADDR_STRING
DhcpServer
As IP_ADDR_STRING
bHaveWins
As Long
PrimaryWinsServer
As IP_ADDR_STRING
SecondaryWinsServer
As IP_ADDR_STRING
LeaseObtained
As Long
LeaseExpires
As Long
End Type
Private Declare Function GetAdaptersInfo Lib "iphlpapi.dll" (pTcpTable As Any, _
pdwSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(dst As Any, src As Any, ByVal bcount As Long)
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
Private Function GetPublicIP()
Dim sSourceUrl As String
Dim sLocalFile As String
Dim hfile
As Long
Dim buff
As String
Dim pos1
As Long
Dim pos2
As Long
'site returning IP address
sSourceUrl = "http://vbnet.mvps.org/resources/tools/getpublicip.shtml"
sLocalFile = "c:\ip.txt"
'ensure this f
|
|