[转帖]PB之获取本机IP
<div style="FONT-SIZE: 13px;">声明win32 API函数:<br/>function int WSAStartup( uint UIVersionRequested, ref s_WSAData lpWSAData ) library "wsock32.dll"<br/>function int WSACleanup() library "wsock32.dll"<br/>function int WSAGetLastError ( ) library "wsock32.dll"<br/>function int gethostname ( ref string name, int namelen ) library "wsock32.dll"<br/>function string GetHost(string lpszhost, ref blob lpszaddress ) library "pbws32.dll" <br/><br/>使用方法:<br/>s_wsadata l_WSAData<br/>string ls_HostName = space(128)<br/>string ls_IpAddress<br/>int li_version = 257<br/>blob{4} lb_hostaddress <br/><br/>IF wsastartup ( li_version, l_WSAData ) = 0 THEN<br/><br/>IF gethostname ( ls_HostName, len(ls_HostName) ) < 0 THEN<br/>messagebox("GetHostName",WSAGetLastError())<br/>ELSE<br/>GetHost(ls_HostName, lb_HostAddress)<br/>ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,1,1))),"000") "."<br/>ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,2,1))),"000") "."<br/>ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,3,1))),"000") "."<br/>ls_IpAddress = string(asc(string(blobmid(lb_HostAddress,4,1))),"000")<br/>END IF<br/>WSACleanup()<br/>ELSE<br/>messagebox("GetHostName",WSAGetLastError())<br/>END IF <br/>sle_1.text=ls_hostname<br/>sle_2.text=ls_ipaddress</div>
页:
[1]