得到機器名稱+得到ip地址

/* ======================================================= */ // 名稱: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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章