I would like to know, if there is a better way to retrieve the IP address list items?
It would be so much easier, if LB would support handling of arrays of pointers natively.
Thanks in advance.
Please use the code in the next post!
Code: |
'GetIP.bas open "Ws2_32.dll" for dll as #Ws2 struct lpWSAData,_ wVersion as word,_ wHighVersion as word,_ szDescription as char[257],_ szSystemStatus as char[129],_ iMaxSockets as ushort,_ iMaxUdpDg as ushort,_ lpVendorInfo as ptr wVersionRequested = hexdec("22") ' initialize wesock calldll #Ws2, "WSAStartup",_ wVersionRequested as word,_ lpWSAData as struct,_ Result as long if Result = 0 then length = 100 hostname$ = space$(length+1) ' get computer name calldll #Ws2, "gethostname",_ hostname$ as ptr,_ length as long,_ Result as long struct hostent,_ hname as ptr,_ haliases as ptr,_ haddrtype as short,_ hlength as short,_ haddrlist as ptr hostentLen = len(hostent.struct) ' dummy to receive pointer to ip address array item struct haddr,_ ip as ptr haddrLen = len(haddr.struct) ' get ip information calldll #Ws2, "gethostbyname",_ hostname$ as ptr,_ phostent as ulong ' copy memory to struct calldll #kernel32, "RtlMoveMemory", _ hostent as struct,_ phostent as ulong, _ hostentLen as ulong, _ Result as void pointer = hostent.haddrlist.struct iplength = hostent.hlength.struct IpAddressArray$ = winstring(pointer) ' cycle through ip address array pointers while IpAddressArray$ <> "" ' copy ip address to dumy structure calldll #kernel32, "RtlMoveMemory", _ haddr as struct,_ pointer as ulong, _ haddrLen as ulong, _ Result as void paddr = haddr.ip.struct ' convert to dotted format for i = 0 to iplength-1 if i = 0 then IPaddress$ = str$(asc(left$(winstring(paddr),1))) else IPaddress$ = IPaddress$; "."; asc(left$(winstring(paddr+i),1)) end if next print IPaddress$ ' advance to next array item pointer = pointer + 4 IpAddressArray$ = winstring(pointer) wend ' close wesock calldll #Ws2, "WSACleanup",_ Result as long end if close #Ws2 |