'If user is not connected to internet, it will return the Lan IPConst MAX_IP = 5' To make a buffer..Type IPINFO dwAddr As Long 'IP address dwIndex As Long' interface index dwMask As Long 'subnet mask dwBCastAddr As Long' broadcast address dwReasmSize As Long 'assembly size unused1 As Integer' not currently used unused2 As Integer '; not currently usedEnd TypeType MIB_IPADDRTABLE dEntrys As Long' number of entries in the table mIPInfo (MAX_IP) As IPINFO 'array of IP address entriesEnd TypeType IP_Array mBuffer As MIB_IPADDRTABLE BufferLen As LongEnd TypePublic Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long to a stringpublic function convey a stringpublic function converadresstostring (longaddr as long) AS STRING DIM MyByte (3) AS BYTE DIM CNT AS Long CopyMemor y myByte (0), longAddr, 4 For Cnt = 0 To 3 ConvertAddressToString = ConvertAddressToString CStr (myByte (Cnt)) Next Cnt ConvertAddressToString = Left $ (ConvertAddressToString, Len (ConvertAddressToString) - 1) "." End FunctionPublic Function GetInternetIP () As String Dim Ret As Long, Tel As Long Dim bBytes () As Byte Dim TempList () As String Dim TempIP As String Dim Tempi As Long Dim Listing As MIB_IPADDRTABLE Dim L3 As String On Error GoTo ErrorEND GetIpAddrTable ByVal 0 &, Ret, True
IF RET <= 0 THEN EXIT FUNCTION Redim Bbytes (0 TO RET - 1) AS BYTE Redim Templist (0 to RET - 1) AS String'Rtrieve The Data Getddddddable Bbytes (0), RET, FALSE
'Get the first 4 bytes to get the entry's .. ip installed copymemory listing.dents, bbytes (0), 4
For tel = 0 to listing.dentrys - 1 'Copy Whole structure to listing .. CopyMemory Listing.MipInfo (Tel), Bbytes (4 (tel * len (0))))))))))))))))) (Tel)) Templist (tel) = convertaddresstostring (Listing.Mipinfo (tel) .dwaddr) Next Tel 'sort out the ip for wan tempip = templist (0) for tempi = 0 to listing.dents - 1 l3 = left (Templist) (TEMPI), 3) IF L3 <> "169" and L3 <> "127" and L3 <> "192" Tempip = Templist (TEMPI) end if next tempi getInternetip = Tempip 'Return Tempip
EXIT FUNCTION
Errornd: GetInternetip = "" End FunctionPrivate Sub Form_Load () MSGBOX GetInternetipend SUB