Reputation: 1523
I have a requirement to ensure that a value is entered in a server for ipv4 ip address, subnet mask, default gateway, a value for DNS and a value for WINS.
I don't necessarily need to check against those values to ensure they are correct since the correct values are pulled from a seperate internal website. I don't have any way to interface with it. So I just want to make sure it is completely entered and ipv6 is not being used.
I can't seem to find anything to help me on this. I looked through the registry to see if I could find anything there to grab.
No luck =/
Any suggestions?
Upvotes: 0
Views: 986
Reputation: 4518
Your question is unclear. It almost sounds like you want to read a value from an input field, but then you say something about the registry. You need to ask more clearly where you are looking for said information.
With that in mind, assuming you mean you want to figure out if the system has acquired an IP address, etc., then consider the following.
1) You can use the Run method and execute ipconfig /all
and parse its results.
2) You can use netsh.exe and parse results. For example:
C:\> netsh interface ipv6 show address
IPv6 is not installed.
There is a lot of information that is able to be gained through this method.
3) You can look in the Registry.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards
usually contains a list of numeric sub-keys. For example, on my system, there is HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\NetworkCards\9
. This key contains values:
Description REG_SZ "Broadcom NetXtreme 57xx Gigabit Controller"
ServiceName REG_SZ "{A1167D26-ADE0-4CDB-B0C6-1F8C5CF9DF5B}"
Of course, that ServiceName GUID will differ. It is unique to each system, but for the following, I will use it in examples. You have to replace it by what your system has.
This points to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\{A1167D26-ADE0-4CDB-B0C6-1F8C5CF9DF5B}\Parameters\Tcpip
where the following values are stored:
"EnableDHCP"=dword:00000001
"IPAddress"=hex(7):30,00,2e,00,30,00,2e,00,30,00,2e,00,30,00,00,00,00,00
"SubnetMask"=hex(7):30,00,2e,00,30,00,2e,00,30,00,2e,00,30,00,00,00,00,00
"DefaultGateway"=hex(7):00,00
"DhcpIPAddress"="10.152.30.49"
"DhcpSubnetMask"="255.255.255.0"
"DhcpServer"="10.152.28.23"
"Lease"=dword:0003f480
"LeaseObtainedTime"=dword:503f5dd6
"T1"=dword:50415816
"T2"=dword:5042d3c6
"LeaseTerminatesTime"=dword:50435256
"DhcpDefaultGateway"=hex(7):31,00,30,00,2e,00,31,00,35,00,32,00,2e,00,33,00,30,\
00,2e,00,31,00,00,00,00,00
"DhcpSubnetMaskOpt"=hex(7):32,00,35,00,35,00,2e,00,32,00,35,00,35,00,2e,00,32,\
00,35,00,35,00,2e,00,30,00,00,00,00,00
It also points to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\Interfaces\{A1167D26-ADE0-4CDB-B0C6-1F8C5CF9DF5B}
where the following values are stored:
"UseZeroBroadcast"=dword:00000000
"EnableDeadGWDetect"=dword:00000001
"EnableDHCP"=dword:00000001
"IPAddress"=hex(7):30,00,2e,00,30,00,2e,00,30,00,2e,00,30,00,00,00,00,00
"SubnetMask"=hex(7):30,00,2e,00,30,00,2e,00,30,00,2e,00,30,00,00,00,00,00
"DefaultGateway"=hex(7):00,00
"DefaultGatewayMetric"=hex(7):00,00
"NameServer"=""
"Domain"=""
"RegistrationEnabled"=dword:00000001
"RegisterAdapterName"=dword:00000000
"TCPAllowedPorts"=hex(7):30,00,00,00,00,00
"UDPAllowedPorts"=hex(7):30,00,00,00,00,00
"RawIPAllowedProtocols"=hex(7):30,00,00,00,00,00
"NTEContextList"=hex(7):30,00,78,00,30,00,30,00,30,00,30,00,30,00,30,00,30,00,\
32,00,00,00,00,00
"DhcpClassIdBin"=hex:
"DhcpServer"="10.152.28.23"
"Lease"=dword:0003f480
"LeaseObtainedTime"=dword:503f5dd6
"T1"=dword:50415816
"T2"=dword:5042d3c6
"LeaseTerminatesTime"=dword:50435256
"IPAutoconfigurationAddress"="0.0.0.0"
"IPAutoconfigurationMask"="255.255.0.0"
"IPAutoconfigurationSeed"=dword:00000000
"AddressType"=dword:00000000
"IsServerNapAware"=dword:00000000
"DhcpIPAddress"="10.152.30.49"
"DhcpSubnetMask"="255.255.255.0"
"DhcpRetryTime"=dword:0001fa40
"DhcpRetryStatus"=dword:00000000
"DhcpNameServer"="10.125.28.23 10.125.28.21 192.168.115.2"
"DhcpDefaultGateway"=hex(7):31,00,30,00,2e,00,31,00,35,00,32,00,2e,00,33,00,30,\
00,2e,00,31,00,00,00,00,00
"DhcpDomain"="my.domain.Local"
"DhcpSubnetMaskOpt"=hex(7):32,00,35,00,35,00,2e,00,32,00,35,00,35,00,2e,00,32,\
00,35,00,35,00,2e,00,30,00,00,00,00,00
This should get you started. Presumably, you can search the registry for {A1167D26-ADE0-4CDB-B0C6-1F8C5CF9DF5B}
for other interesting information relating to your network adapter. For example:
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Dhcp\Parameters\...
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\LanmanServer\Linkage\...
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\lanmanworkstation\Linkage\...
... and so on ...
Each of those locations is rich with cross-references and data about the network sub-system.
4) See also Get active network interface on Windows. In particular, look at the answer that starts out:
You don't need make a new API. Use the WMI class from VBScript.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa394216(v=vs.85).aspx
5) A link of helpful WMIC commands is here: WMIC-Snippets > NIC properties
Upvotes: 1