IanM posted this snippet on Jan 5th
It works.
sync on
if WSAStartup() = 0
print GetLocalIP(0)
print GetLocalIP(1)
WSACleanup()
endif
sync
sync
wait key
end
function GetLocalIP(index as integer)
local ip as string
local p as DWORD
local HOSTENT as DWORD
HOSTENT=make memory(256)
if GetHostName( HOSTENT, 256 ) = 0
HostInfo=GetHostByName( HOSTENT )
if HostInfo <> 0
p=HostInfo+12
p=*p
p=*p
p=p+(index*4)
ip=INET_ntoa( *p )
endif
endif
delete memory HOSTENT
endfunction ip
function GetHostName(memptr as DWORD, size as integer)
local r as integer
local a as DWORD
local s as DWORD
r=call dll(201, "gethostname", memptr, size)
endfunction r
function GetHostByName(memptr as DWORD)
local r as integer
r=call dll(201, "gethostbyname", memptr)
endfunction r
function INET_ntoa(addr as DWORD)
local ip as string
ip=call dll(201, "inet_ntoa", addr)
endfunction ip
function WSAStartup()
local WSADATA as DWORD
local r as integer
local v as WORD
load dll "wsock32.dll",201
WSADATA=make memory(16384)
v=2
r=call dll(201, "WSAStartup", v, WSADATA)
delete memory WSADATA
endfunction r
function WSACleanup()
call dll 201, "WSACleanup"
delete dll 201
endfunction
The more you see, the more you know.
The more you know, the more you see.