用Windows API调用实现域名解析
DECLARE INTEGER WSACleanup IN ws2_32
DECLARE STRING inet_ntoa IN ws2_32 INTEGER in_addr
DECLARE INTEGER gethostbyname IN ws2_32 STRING host
DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING lpWSAData
DECLARE RtlMoveMemory IN kernel32 As CopyMemory;
STRING @Dest, INTEGER Src, INTEGER nLength
IF WSAStartup(0x202, Repli(Chr(0),512)) = 0
&& initiates use of WS2_32.DLL
?getip('www.')
= WSACleanup()
ENDIF
FUNCTION GetIP(cServer)
#DEFINE HOSTENT_SIZE 16
LOCAL nStruct, nSize, cBuffer, nAddr, cIP
nStruct = gethostbyname(cServer)
IF nStruct = 0
RETURN '0.0.0.0'
ENDIF
cBuffer = Repli(Chr(0), HOSTENT_SIZE)
cIP = Repli(Chr(0), 4)
= CopyMemory(@cBuffer, nStruct, HOSTENT_SIZE)
= CopyMemory(@cIP, buf2dword(SUBS(cBuffer,13,4)),4)
= CopyMemory(@cIP, buf2dword(cIP),4)
RETURN inet_ntoa(buf2dword(cIP))
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(lcBuffer, 1,1)) + ;
Bitlshift(Asc(SUBS(lcBuffer, 2,1)),8) +;
Bitlshift(Asc(SUBS(lcBuffer, 3,1)),16) +;
Bitlshift(Asc(SUBS(lcBuffer, 4,1)),24)