Dans un module et juste aprés option explicite, coller la déclaration de ces variables:
Const MAX_IP = 5 ' --créer un buffer ... je pense pas que vous en avez plus que 5
Type IPINFO
dwAddr AsLong ' -- adresse IP
dwIndex AsLong
dwMask AsLong
dwBCastAddr AsLong
dwReasmSize AsLong
unused1 AsInteger
unused2 AsIntegerEnd Type
Type MIB_IPADDRTABLE
dEntrys AsLong
mIPInfo(MAX_IP) As IPINFO
End Type
Type IP_Array
mBuffer As MIB_IPADDRTABLE
BufferLen AsLongEnd Type
PublicDeclareSub CopyMemory Lib"kernel32"Alias"RtlMoveMemory" (destination As Any, Source As Any, ByVal Length AsLong)
PublicDeclareFunction GetIpAddrTable Lib"IPHlpApi" (pIPAdrTable AsByte, pdwSize AsLong, ByVal Sort AsLong) AsLong
' --convertion d'un Long vers un string
PublicFunction ConvertAddressToString(longAddr AsLong) AsStringDim myByte(3) AsByteDim Cnt AsLong
CopyMemory myByte(0), longAddr, 4
For Cnt = 0 To 3
ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."Next Cnt
ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
EndFunction
Maintenant, sur l'évenement click du bouton IP:
' --Déterminer l'adresse IP
PublicFunction Get_IP_Click() AsStringDim Ret AsLong, Tel AsLongDim bBytes() AsByteDim TempList() AsStringDim TempIP AsStringDim Tempi AsLongDim Listing As MIB_IPADDRTABLE
Dim L3 AsStringOnErrorGoTo END1
GetIpAddrTable ByVal 0&, Ret, TrueIf Ret <= 0 ThenExitFunction
ReDim bBytes(0 To Ret - 1) AsByte
ReDim TempList(0 To Ret - 1) AsString
GetIpAddrTable bBytes(0), Ret, False
CopyMemory Listing.dEntrys, bBytes(0), 4
For Tel = 0 To Listing.dEntrys - 1
CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
TempList(Tel) = ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr)
Next Tel
TempIP = TempList(0)
For Tempi = 0 To Listing.dEntrys - 1
L3 = Left(TempList(Tempi), 3)
If L3 <> "169"And L3 <> "127"And L3 <> "192"Then
TempIP = TempList(Tempi)
EndIfNext Tempi
GetWanIP = TempIP 'Return The TempIPExitFunction
END1:
GetWanIP = ""EndFunction