/* ======================================================= */ // 名稱:gf_GetHostIp() // 作用:得到ip地址 // 參數:無 // 返回值:STRING //返回:"機器名稱:Ip地址" // 完成:woods // 注:需註冊函數 // 取ip地址函數 // 所需調用函數: //FUNCTION uLong WSACleanup() Library "wsock32.dll" //FUNCTION uLong WSAStartup(long wVersionRequired,ref WSAData lpWSADATA) Library "wsock32.dll" //FUNCTION uLong gethostbyname(string sHost) Library "wsock32.dll" //FUNCTION uLong gethostname(ref string szHost,long dwHostlen) Library "wsock32.dll" // //FUNCTION uLong RtlMoveMemory(ref hostent hpvDest,long hpvSource,long cbCopy) Library "kernel32.dll" //FUNCTION uLong RtlMoveMemory(ref Long hpvDest,long hpvSource,long cbCopy) Library "kernel32.dll" //FUNCTION uLong RtlMoveMemory(ref uLong hpvDest,long hpvSource,long cbCopy) Library "kernel32.dll" //FUNCTION uLong RtlMoveMemory(ref char hpvDest,long hpvSource,long cbCopy) Library "kernel32.dll" // //FUNCTION STRING inet_ntoa(ulong ulAddr) LIBRARY "wsock32.dll" /* ======================================================= */ wsadata wsd; string hn; hostent ht; ulong ul_h,uaddr; long s,ui,i; char ch; String ls_Name,ls_Ip
WSAStartup(257,ref wsd);
hn=space(255);
if gethostname(ref hn,255)<>0 then return ''; end if hn=trim(hn) ls_Name=hn; ul_h=gethostbyname(hn)
if ul_h=0 then return ''; end if
RtlMoveMemory(ref ht,ul_h,16)
if ht.hname=0 then return ''; end if
RtlMoveMemory(ref ch,ht.hname,1) i=0;
do while asc(ch)<>0 i++; RtlMoveMemory(ref ch,ht.hname+i,1) loop
if ht.haddrlist=0 then return ''; end if
RtlMoveMemory(ref ui,ht.haddrlist,4)
if ui<>0 then RtlMoveMemory(ref uaddr,ui,ht.hlen) ls_IP=inet_ntoa(uaddr) end if
WSACleanup()
return ls_name+':'+ls_ip