Another way to obtain the local IP address in Pb

Source: Internet
Author: User

Another way to obtain the local IP address in Pb

Generally, run ("regsvr32/s mswinsck. ocx") is used for registration to obtain information about the local machine, including IP addresses.
This section describes how to obtain the IP address of the Local Machine by accessing the registry. Because other people's controls are not used, the program is "independent.

Getenvironment (ge_env)
Choose case ge_env.ostype
// AIX !, HPUX !, Macintosh !, Osf1 !, Sol2 !, Windows !, Wondowsnt!
Case windows!
Gs_ostype = "Windows"
Case WindowsNT!
Gs_ostype = "WindowsNT"
Case else
Gs_ostype = "other"
End choose

// Use the registry to retrieve the local IP Address
String ls_value = ""
String subkeys []
Choose case gs_ostype
Case 'windows'
String skey = 'HKEY _ LOCAL_MACHINE/system/CurrentControlSet/services/class/nettrans'
String sname = 'ipaddress'
Int I
String skey1
Ls_value =''
Registrykeys (skey, subkeys)
If upperbound (subkeys)> 0 then
For I = 1 to upperbound (subkeys)
Skey1 = skey + '/' + subkeys [I]
If registryget (skey1, sname, ls_value) = 1 then
If ls_value <> '0. 0.0.0 'then
Exit
End if
End if
Next
End if
Case "WindowsNT"
String ls_keynt1 = 'HKEY _ LOCAL_MACHINE/software/Microsoft/Windows NT/CurrentVersion/networkcards'
If registrykeys (ls_keynt1, subkeys) = 1 then
If upperbound (subkeys)> 0 then
Ls_keynt1 = ls_keynt1 + '/' + subkeys [1]
End if
End if
// Bill TCPIP may need to query all the sub-items in the ls_keynt1 field, which mainly means that the last item 6 is different on different machines.
String ls_keynt2 = 'HKEY _ LOCAL_MACHINE/system/CurrentControlSet/services /'
String ls_keynt3 = '/parameters/tcpip'
String ls_name_nt1 = 'servicename'
String ls_name_nt2 = 'ipaddress'
String ls_name_nt3 =''
String ls_value2 []
If registryget (ls_keynt1, ls_name_nt1, ls_value) = 1 then
Ls_name_nt3 = ls_keynt2 + ls_value + ls_keynt3
If registryget (ls_name_nt3, ls_name_nt2, regmultistring !, Ls_value2) = 1 then
Ls_value = ls_value2 [1]
Else
// Multiple IP addresses may exist. ls_value = ls_value2 [1] + ";" + ls_value2 [2]
Ls_value = ls_value2 [1]
End if
Else
Ls_value =''
End if
Case else
Ls_value =''
Return
End choose
Gs_ipaddress = ls_value

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.