JohnPhan 发表于 2007-7-16 11:26:10

pb中获得本机IP地址的另一个方法

<p>一般人多用run("regsvr32 /s MSWINSCK.OCX")注册后,利用这个控件,获得包括IP地址在内的本机各种信息。</p><p>这里介绍的是&nbsp; 利用访问注册表的方法,来获得本机的IP地址。因为没有利用别人的控件,程序更“独立”了。</p><p>GetEnvironment(ge_env) <br/>CHOOSE CASE ge_env.OSType<br/>//aix!, hpux!, macintosh!, osf1!, sol2!, windows!, wondowsnt!<br/>&nbsp;CASE Windows!<br/>&nbsp;&nbsp;gs_OStype = "Windows"<br/>&nbsp;CASE WindowsNT!<br/>&nbsp;&nbsp;gs_OStype = "WindowsNT"<br/>&nbsp;CASE ELSE<br/>&nbsp;&nbsp;gs_OStype = "Other"&nbsp;&nbsp;&nbsp;<br/>END CHOOSE</p><p></p><p>//使用注册表取本机IP地址<br/>String ls_value = ""<br/>String subkeys[]<br/>CHOOSE CASE gs_OStype<br/>&nbsp;CASE 'Windows'<br/>&nbsp;&nbsp;String skey = 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\NetTrans'<br/>&nbsp;&nbsp;String sname = 'IPAddress'<br/>&nbsp;&nbsp;Int i<br/>&nbsp;&nbsp;String skey1<br/>&nbsp;&nbsp;ls_value = ''<br/>&nbsp;&nbsp;RegistryKeys ( skey, subkeys )<br/>&nbsp;&nbsp;IF UpperBound(subkeys) &gt; 0 THEN<br/>&nbsp;&nbsp;&nbsp;FOR i = 1 To UpperBound(subkeys)<br/>&nbsp;&nbsp;&nbsp;&nbsp;skey1 = skey+'\'+subkeys<br/>&nbsp;&nbsp;&nbsp;&nbsp;IF RegistryGet(skey1,sname,ls_value) = 1 THEN<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;IF ls_value &lt;&gt; '0.0.0.0' THEN<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;EXIT<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;END IF<br/>&nbsp;&nbsp;&nbsp;&nbsp;END IF<br/>&nbsp;&nbsp;&nbsp;NEXT<br/>&nbsp;&nbsp;END IF<br/>&nbsp;CASE "WindowsNT"<br/>&nbsp;&nbsp;String ls_keynt1 = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards'<br/>&nbsp;&nbsp;IF RegistryKeys (ls_keynt1,subkeys ) = 1 THEN<br/>&nbsp;&nbsp;&nbsp;IF UpperBound(subkeys) &gt; 0 THEN<br/>&nbsp;&nbsp;&nbsp;&nbsp;ls_keynt1 = ls_keynt1+'\'+subkeys<br/>&nbsp;&nbsp;&nbsp;END IF<br/>&nbsp;&nbsp;END IF<br/>&nbsp;&nbsp;//bill Tcpip 可能需要查询 ls_keynt1 字段所有的子项,主要是指:最后一个项 6 在不同的机器上是不一样的<br/>&nbsp;&nbsp;String ls_keynt2 = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\'<br/>&nbsp;&nbsp;String ls_keynt3 = '\Parameters\Tcpip'<br/>&nbsp;&nbsp;String ls_name_nt1 = 'ServiceName'<br/>&nbsp;&nbsp;String ls_name_nt2 = 'IPAddress'<br/>&nbsp;&nbsp;String ls_name_nt3 = ''<br/>&nbsp;&nbsp;String ls_value2[]<br/>&nbsp;&nbsp;IF RegistryGet(ls_keynt1,ls_name_nt1,ls_value) = 1 THEN<br/>&nbsp;&nbsp;&nbsp;ls_name_nt3 = ls_keynt2+ls_value+ls_keynt3<br/>&nbsp;&nbsp;&nbsp;IF RegistryGet(ls_name_nt3,ls_name_nt2,RegMultiString!,ls_value2) = 1 THEN<br/>&nbsp;&nbsp;&nbsp;&nbsp;ls_value = ls_value2<br/>&nbsp;&nbsp;&nbsp;ELSE<br/>&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;&nbsp;&nbsp;可能有多个ip地址 &nbsp;ls_value = ls_value2 + " ; " + ls_value2<br/>&nbsp;&nbsp;&nbsp;&nbsp;ls_value = ls_value2<br/>&nbsp;&nbsp;&nbsp;END IF<br/>&nbsp;&nbsp;ELSE<br/>&nbsp;&nbsp;&nbsp;ls_value = ''<br/>&nbsp;&nbsp;END IF<br/>&nbsp;CASE ELSE<br/>&nbsp;&nbsp;ls_value = ''<br/>&nbsp;&nbsp;RETURN<br/>END CHOOSE<br/>gs_ipaddress&nbsp; = ls_value</p>
[此贴子已经被作者于2007-8-21 8:47:16编辑过]

yifeng28 发表于 2007-9-17 09:09:53

<p>查注册表也是够辛苦的.</p><p>不过好不错, 支持一下!</p>
页: [1]
查看完整版本: pb中获得本机IP地址的另一个方法

免责声明:
本站所发布的一切破解补丁、注册机和注册信息及软件的解密分析文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:Admin@SybaseBbs.com