纯PB代码实现取MAC和IP(PB9)

<p><span style="color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; background-color: rgb(255, 255, 255);">1、定义一个名为s_wsadata的结构,如下:</span></p><pre class="brush:delphi;toolbar:false">&nbsp;&nbsp;unsignedinteger&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version &nbsp;&nbsp;unsignedinteger&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;highversion &nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;discription[257] &nbsp;&nbsp;character&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;systemstatus[129] &nbsp;&nbsp;unsignedinteger&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxsockets &nbsp;&nbsp;unsignedinteger&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maxupddg &nbsp;&nbsp;string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vendorinfo</pre><p><span style="color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; background-color: rgb(255, 255, 255);"></span><span style="color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; background-color: rgb(255, 255, 255);">二、在Local&nbsp;External&nbsp;Funtions中作如下的声明:</span></p><pre class="brush:delphi;toolbar:false">function&nbsp;int&nbsp;WSAStartup(&nbsp;uint&nbsp;UIVersionRequested,&nbsp;ref&nbsp;s_WSAData&nbsp;lpWSAData&nbsp;)&nbsp;&nbsp;library&nbsp;&quot;wsock32.dll&quot; &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;int&nbsp;WSACleanup()&nbsp;library&nbsp;&quot;wsock32.dll&quot; &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;int&nbsp;WSAGetLastError&nbsp;(&nbsp;)&nbsp;library&nbsp;&quot;wsock32.dll&quot; &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;int&nbsp;gethostname&nbsp;(&nbsp;ref&nbsp;string&nbsp;name,&nbsp;int&nbsp;namelen&nbsp;)&nbsp;library&nbsp;&quot;wsock32.dll&quot; &nbsp;&nbsp;&nbsp;&nbsp;function&nbsp;string&nbsp;GetHost(string&nbsp;lpszhost,&nbsp;ref&nbsp;blob&nbsp;lpszaddress&nbsp;)&nbsp;library&nbsp;&quot;pbws32.dll&quot;</pre><p><span style="color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; background-color: rgb(255, 255, 255);"></span><span style="color: rgb(79, 79, 79); font-family: &quot;Microsoft YaHei&quot;, &quot;SF Pro Display&quot;, Roboto, Noto, Arial, &quot;PingFang SC&quot;, sans-serif; background-color: rgb(255, 255, 255);">三、使用方法:</span></p><pre class="brush:vb;toolbar:false;">s_wsadata &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;l_WSAData string ls_HostName&nbsp;=&nbsp;space(128)&nbsp;&nbsp;&nbsp; string ls_IpAddress int li_version&nbsp;=&nbsp;257 blob{4}&nbsp; lb_hostaddress&nbsp; IF&nbsp;wsastartup&nbsp;(&nbsp;li_version,&nbsp;l_WSAData&nbsp;)&nbsp;=&nbsp;0&nbsp;THEN IF&nbsp;gethostname&nbsp;(&nbsp;ls_HostName,&nbsp;len(ls_HostName)&nbsp;)&nbsp;&lt;&nbsp;0&nbsp;THEN messagebox(&quot;GetHostName&quot;,WSAGetLastError()) ELSE GetHost(ls_HostName,&nbsp;lb_HostAddress) ls_IpAddress&nbsp;=&nbsp;string(asc(string(blobmid(lb_HostAddress,1,1))),&quot;000&quot;)&nbsp;+&nbsp;&quot;.&quot; ls_IpAddress&nbsp;+=&nbsp;string(asc(string(blobmid(lb_HostAddress,2,1))),&quot;000&quot;)&nbsp;+&nbsp;&quot;.&quot; ls_IpAddress&nbsp;+=&nbsp;string(asc(string(blobmid(lb_HostAddress,3,1))),&quot;000&quot;)&nbsp;+&nbsp;&quot;.&quot; ls_IpAddress&nbsp;+=&nbsp;string(asc(string(blobmid(lb_HostAddress,4,1))),&quot;000&quot;) END&nbsp;IF WSACleanup() ELSE messagebox(&quot;GetHostName&quot;,WSAGetLastError()) END&nbsp;IF&nbsp; messagebox(&#39;ls_hostname:&nbsp;&#39;+ls_hostname,&#39;ls_ipaddress:&nbsp;&#39;+ls_ipaddress)</pre><pre class="brush:c#;toolbar:false">//函数名称:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f_getip&nbsp; //调用方法:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;f_getip(ip_name)&nbsp; //参数说明:&nbsp;&nbsp;&nbsp;ip_name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;&nbsp;类型:integer&nbsp;&nbsp;&nbsp;含义:确定返回的结果(1:机名和IP地址,2:机名,3:IP地址,4:mac地址)&nbsp; //返回结果:&nbsp;&nbsp;&nbsp;string&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:由ip_name决定的反回结果&nbsp; //函数功能:&nbsp;&nbsp;&nbsp;得到本机的名和IP地址&nbsp; //设计者:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;时间:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //建立全局的结构s_wsadata&nbsp; //结构如下:&nbsp; //version&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsignedinteger&nbsp; //highversion&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unsignedinteger&nbsp; //description[257]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;character&nbsp; //systemstatus[129]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n