Multiple addresses are returned, seperated by a newline, if available.
Note! If a domain has no dedicated IP address because it is run from a server using virtual hosts the IP address of the server is returned.
The script below is fully functional as given, just copy and paste it (beware of line breaks) into a script file.
(largely based on functions from the WinLirc script and various other posts in this forum)
NodeName = www.google.com IPs := HostToIp(NodeName) DllCall("Ws2_32\WSACleanup") ; always inlude this line after calling to release the socket connection if IPs <> -1 ; no error occurred Msgbox, %NodeName%`n%IPs% else MsgBox, Host "%NodeName%" not found HostToIp(NodeName) ; returns -1 if unsuccessfull or a newline seperated list of valid IP addresses on success { VarSetCapacity(wsaData, 32) ; The struct is only about 14 in size, so 32 is conservative. result := DllCall("Ws2_32\WSAStartup", "UShort", 0x0002, "UInt", &wsaData) ; Request Winsock 2.0 (0x0002) if ErrorLevel ; check ErrorLevel to see if the OS has Winsock 2.0 available: { MsgBox WSAStartup() could not be called due to error %ErrorLevel%. Winsock 2.0 or higher is required. return -1 } if result ; Non-zero, which means it failed (most Winsock functions return 0 on success). { MsgBox % "WSAStartup() indicated Winsock error " . DllCall("Ws2_32\WSAGetLastError") ; % return -1 } PtrHostent := DllCall("Ws2_32\gethostbyname", str, Nodename) if (PtrHostent = 0) Return -1 VarSetCapacity(hostent,16,0) DllCall("RtlMoveMemory",UInt,&hostent,UInt,PtrHostent,UInt,16) h_name := ExtractInteger(hostent,0,false,4) h_aliases := ExtractInteger(hostent,4,false,4) h_addrtype := ExtractInteger(hostent,8,false,2) h_length := ExtractInteger(hostent,10,false,2) h_addr_list := ExtractInteger(hostent,12,false,4) ; Retrieve official name VarSetCapacity(Name,64,0) DllCall("RtlMoveMemory",UInt,&Name,UInt,h_name,UInt,64) ; Retrieve Aliases VarSetCapacity(Aliases,12,0) DllCall("RtlMoveMemory", UInt, &Aliases, UInt, h_aliases, UInt, 12) Loop, 3 { offset := ((A_Index-1)*4) PtrAlias%A_Index% := ExtractInteger(Aliases,offset,false,4) If (PtrAlias%A_Index% = 0) break VarSetCapacity(Alias%A_Index%,64,0) DllCall("RtlMoveMemory",UInt,&Alias%A_Index%,UInt,PtrAlias%A_Index%,Uint,64) } VarSetCapacity(AddressList,12,0) DllCall("RtlMoveMemory",UInt,&AddressList,UInt,h_addr_list,UInt,12) Loop, 3 { offset := ((A_Index-1)*4) PtrAddress%A_Index% := ExtractInteger(AddressList,offset,false,4) If (PtrAddress%A_Index% =0) break VarSetCapacity(address%A_Index%,4,0) DllCall("RtlMoveMemory" ,UInt,&address%A_Index%,UInt,PtrAddress%A_Index%,Uint,4) i := A_Index Loop, 4 { if Straddress%i% Straddress%i% := Straddress%i% "." ExtractInteger(address%i%,(A_Index-1 ),false,1) else Straddress%i% := ExtractInteger(address%i%,(A_Index-1 ),false,1) } Straddress0 = %i% } loop, %Straddress0% ; put them together and return them { _this := Straddress%A_Index% if _this <> IPs = %IPs%%_this% if A_Index = %Straddress0% break IPs = %IPs%`n } return IPs } ExtractInteger(ByRef pSource, pOffset = 0, pIsSigned = false, pSize = 4) { Loop %pSize% result += *(&pSource+pOffset+A_Index-1) << 8*A_Index-8 Return result }