Allows you to retrieve an IP address of the specified hostname (ie. www.aol.com).
#constant DLL_WINSOCK2 255
print GetDnsLookup("www.aol.com")
wait key
end
function GetDnsLookup(address as string)
local ipResult as string
local weLoaded as boolean
local tempMem as dword
` Load Winsock DLL if not already loaded
if dll exist(DLL_WINSOCK2) = 0
load dll "ws2_32.dll", DLL_WINSOCK2
weLoaded = 1
endif
` Start Winsock
tempMem = make memory(400)
call dll DLL_WINSOCK2, "WSAStartup", 0x0202, tempMem
delete memory tempMem
` Perform lookup
tempMem = call dll(DLL_WINSOCK2, "gethostbyname", address)
if tempMem <> 0
inc tempMem, 12
tempMem = *tempMem
tempMem = *tempMem
` Store address
for x = 1 to 3
ipResult = ipResult + str$((*tempMem) && 0xFF) + "."
inc tempMem
next x
ipResult = ipResult + str$((*tempMem) && 0xFF)
endif
` Shutdown Winsock
call dll DLL_WINSOCK2, "WSACleanup"
` Unload DLL if we loaded it
if weLoaded then delete dll DLL_WINSOCK2
endfunction ipResult