IpConfig plugin

From NSIS Wiki


Contents

[edit] Links

IpConfig.zip (141 KB)

IpConfig plugin thread on NSIS Discussion forum

[edit] Description

Version: 0.1.

With the IpConfig plugin you can query all kinds of network info, mainly the same info you get with the shell command ipconfig /all. Both an ANSI as well as a Unicode plugin DLL is available.

[edit] Functions

All functions returns 2 values:
- "ok" or "error"
- The requested value if "ok", an error message if "error"

[edit] GetHostName

IpConfig::GetHostName
Gets the hostname of the computer.
Return value
The hostname of the computer.

More info on MS TechNet

[edit] GetPrimaryDNSSuffix

IpConfig::GetPrimaryDNSSuffix
Gets the Primary DNS Suffix of the computer.
Return value
The Primary DNS Suffix of the computer.

[edit] GetNodeType

IpConfig::GetNodeType
Gets the Node Type of the computer.
Possible return values
- Broadcast (B-node)
- Peer-Peer (P-node)
- Mixed (M-node)
- Hybrid (H-node)
- Unknown

More info on MS TechNet

[edit] IsIPRoutingEnabled

IpConfig::IsIPRoutingEnabled
Checks if IP Routing is enabled on the computer.
Possible return values
- Yes
- No

More info on MS TechNet

[edit] IsWINSProxyEnabled

IpConfig::IsWINSProxyEnabled
Checks if WINS Proxy is enabled on the computer.
Possible return values
- Yes
- No

More info on MSDN (DNSEnabledForWINSResolution)

[edit] GetDNSSuffixSearchList

IpConfig::GetDNSSuffixSearchList
Gets the DNS Suffix SearchList of the computer.
Return value
The DNS Suffix SearchList of the computer.

[edit] GetAllNetworkAdaptersIDsCB

IpConfig::GetAllNetworkAdaptersIDsCB CallbackAddress
Finds the ID's from all installed Networkadapters.
The use of this function is not recommended, use GetEnabledNetworkAdaptersIDsCB instead.
Parameters
CallbackAddress: For each ID found the function on this address is called after the ID is pushed to the stack.
Return value
The number of Network adapters found.

More info on MSDN

[edit] GetAllNetworkAdaptersIDs

IpConfig::GetAllNetworkAdaptersIDs
Finds the ID's from all installed Networkadapters.
The use of this function is not recommended, use GetEnabledNetworkAdaptersIDs instead.
Return value
All found ID's in a space seperated string.

More info on MSDN

[edit] GetEnabledNetworkAdaptersIDsCB

IpConfig::GetEnabledNetworkAdaptersIDsCB CallbackAddress
Finds the ID's from all installed Networkadapters which are enabled.
These are the active Network adapters.
Parameters
CallbackAddress: For each ID found the function on this address is called after the ID is pushed to the stack.
Return value
The number of Network adapters found.

More info on MSDN (IPEnabled)

[edit] GetEnabledNetworkAdaptersIDs

IpConfig::GetEnabledNetworkAdaptersIDs  
Finds the ID's from all installed Networkadapters which are enabled.
These are the active Network adapters.
Return value
All found ID's in a space seperated string.

More info on MSDN (IPEnabled)

[edit] GetNetworkAdapterIDFromDescription

IpConfig::GetNetworkAdapterIDFromDescription Description
Gets the ID from the NetworkAdapter with the given Description.
Parameters
Description: The description to look for.
Return value
The ID from the NetworkAdapter with the given Description.

More info on MSDN (Description)

[edit] GetNetworkAdapterIDFromMACAddress

IpConfig::GetNetworkAdapterIDFromMACAddress MACAddress
Gets the ID from the NetworkAdapter with the given MAC Address.
Parameters
MACAddress: The MAC Address to look for.
Return value
The ID from the NetworkAdapter with the given MAC Address.

More info on MSDN (MACAddress)

[edit] GetNetworkAdapterIDFromIPAddress

IpConfig::GetNetworkAdapterIDFromIPAddress IPAddress
Gets the ID from the NetworkAdapter with the given IP Address.
NOTE: only the first hit will be returned.
Parameters
IPAddress: The IP Address to look for.
Return value
The ID from the NetworkAdapter with the given IP Address.

More info on MSDN (IPAddress)

[edit] GetNetworkAdapterType

IpConfig::GetNetworkAdapterType NetworkAdapterID
Gets the Type of the given Networkadapter.
Parameters
NetworkAdapterID
Possible return values (See link below for a complete list)
- Ethernet 802.3
- Token Ring 802.5
- Wide Area Network (WAN)
- Wireless

More info on MSDN (AdapterType)

[edit] GetNetworkAdapterConnectionID

IpConfig::GetNetworkAdapterConnectionID NetworkAdapterID
Gets the Connection ID of the given Networkadapter.
This is the Name of the network connection as it appears in the Network Connections Control Panel program.
Parameters
NetworkAdapterID
Return value
The Connection ID of the given Networkadapter.

More info on MSDN (NetConnectionID)

[edit] GetNetworkAdapterConnectionSpecificDNSSuffix

IpConfig::GetNetworkAdapterConnectionSpecificDNSSuffix NetworkAdapterID
Gets the DNS Suffix of the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The DNS Suffix of the given Networkadapter.

More info on MSDN (DNSDomain)

[edit] GetNetworkAdapterDescription

IpConfig::GetNetworkAdapterDescription NetworkAdapterID
Gets the Description of the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The Description of the given Networkadapter.

More info on MSDN (Description)

[edit] GetNetworkAdapterMACAddress

IpConfig::GetNetworkAdapterMACAddress NetworkAdapterID
Gets the MAC Address of the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The MAC Address of the given Networkadapter.

More info on MSDN (MACAddress)

[edit] IsNetworkAdapterDHCPEnabled

IpConfig::IsNetworkAdapterDHCPEnabled NetworkAdapterID
Checks if DHCP is enabled for the given Networkadapter.
Parameters
NetworkAdapterID
Possible return values
- Yes
- No

More info on MSDN (DHCPEnabled)

[edit] IsNetworkAdapterAutoSense

IpConfig::IsNetworkAdapterAutoSense NetworkAdapterID
Checks if the given Networkadapter can automatically determine the speed of the attached network media.
Parameters
NetworkAdapterID
Possible return values
- Yes
- No

More info on MSDN (AutoSense)

[edit] GetNetworkAdapterIPAddressesCB

IpConfig::GetNetworkAdapterIPAddressesCB NetworkAdapterID CallbackAddress
Finds the IP addresses for the given Networkadapter.
Parameters
NetworkAdapterID
CallbackAddress: For each IP address found the function on this address is called after the IP address is pushed to the stack.
Return value
The number of IP addresses found.

More info on MSDN (IPAddress)

[edit] GetNetworkAdapterIPAddresses

IpConfig::GetNetworkAdapterIPAddresses NetworkAdapterID
Finds the IP addresses for the given Networkadapter.
Parameters
NetworkAdapterID
Return value
All found IP addresses in a space seperated string.

More info on MSDN (IPAddress)

[edit] GetNetworkAdapterIPSubNetsCB

IpConfig::GetNetworkAdapterIPSubNetsCB NetworkAdapterID CallbackAddress
Finds the subnet masks associated with the given Networkadapter.
Parameters
NetworkAdapterID
CallbackAddress: For each subnet mask found the function on this address is called after the subnet mask is pushed to the stack.
Return value
The number of subnet masks found.

More info on MSDN (IPSubnet)

[edit] GetNetworkAdapterIPSubNets

IpConfig::GetNetworkAdapterIPSubNets NetworkAdapterID
Finds the subnet masks associated with the given Networkadapter.
Parameters
NetworkAdapterID
Return value
All found subnet masks in a space seperated string.

More info on MSDN (IPSubnet)

[edit] GetNetworkAdapterDefaultIPGatewaysCB

IpConfig::GetNetworkAdapterDefaultIPGatewaysCB NetworkAdapterID CallbackAddress
Finds the IP addresses of default gateways for the given Networkadapter.
Parameters
NetworkAdapterID
CallbackAddress: For each IP address found the function on this address is called after the IP address is pushed to the stack.
Return value
The number of IP addresses found.

More info on MSDN (DefaultIPGateway)

[edit] GetNetworkAdapterDefaultIPGateways

IpConfig::GetNetworkAdapterDefaultIPGateways NetworkAdapterID
Finds the IP addresses of default gateways for the given Networkadapter.
Parameters
NetworkAdapterID
Return value
All found IP addresses in a space seperated string.

More info on MSDN (DefaultIPGateway)

[edit] GetNetworkAdapterDHCPServer

IpConfig::GetNetworkAdapterDHCPServer NetworkAdapterID
Gets the IP address of the DHCP server of the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The IP address of the DHCP server of the given Networkadapter.

More info on MSDN (DHCPServer)

[edit] GetNetworkAdapterDNSServersCB

IpConfig::GetNetworkAdapterDNSServersCB NetworkAdapterID CallbackAddress
Finds the server IP addresses to be used in querying for DNS servers on the given Networkadapter.
Parameters
NetworkAdapterID
CallbackAddress: For each IP address found the function on this address is called after the IP address is pushed to the stack.
Return value
The number of IP addresses found.

More info on MSDN (DNSServerSearchOrder)

[edit] GetNetworkAdapterDNSServers

IpConfig::GetNetworkAdapterDNSServers NetworkAdapterID
Finds the server IP addresses to be used in querying for DNS servers on the given Networkadapter.
Parameters
NetworkAdapterID
Return value
All found IP addresses in a space seperated string.

More info on MSDN (DNSServerSearchOrder)

[edit] GetNetworkAdapterPrimaryWINSServer

IpConfig::GetNetworkAdapterPrimaryWINSServer NetworkAdapterID
Gets the IP address for the primary WINS server of the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The IP address of the primary WINS server of the given Networkadapter.

More info on MSDN (WINSPrimaryServer)

[edit] GetNetworkAdapterSecondaryWINSServer

IpConfig::GetNetworkAdapterSecondaryWINSServer NetworkAdapterID
Gets the IP address for the secondary WINS server of the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The IP address of the secondary WINS server of the given Networkadapter.

More info on MSDN (WINSSecondaryServer)

[edit] GetNetworkAdapterDHCPLeaseObtained

IpConfig::GetNetworkAdapterDHCPLeaseObtained NetworkAdapterID
Gets the date and time when DHCP was obtained for the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The date and time when DHCP will expire for the given Networkadapter.
Format: "{Day}.{Month}.{Year} {Hour}:{Minute}:{Second}" (Compatible with the Time plugin).

More info on MSDN (DHCPLeaseExpires)

[edit] GetNetworkAdapterDHCPLeaseExpires

IpConfig::GetNetworkAdapterDHCPLeaseExpires NetworkAdapterID
Gets the date and time when DHCP will expire for the given Networkadapter.
Parameters
NetworkAdapterID
Return value
The date and time when DHCP will expire for the given Networkadapter.
Format: "{Day}.{Month}.{Year} {Hour}:{Minute}:{Second}" (Compatible with the Time plugin).

More info on MSDN (DHCPLeaseExpires)

[edit] Examples

[edit] IpConfig /all (using callbacks)

This example imitates the ipconfig /all command.
!Macro ShowResult ItemString
	Pop $0 
	Pop $1 
	${if} $0 == "ok" 
		DetailPrint "${ItemString} $1" 
	${Else} 
		DetailPrint "${ItemString} Error: $1" 
	${EndIf} 
!MacroEnd 
 
!Macro ShowMultiResult ItemString
	Pop $0 
	Pop $1 
	${if} $0 != "ok" 
		DetailPrint "${ItemString} Error: $1" 
	${EndIf} 
!MacroEnd 
 
Section 
	DetailPrint "Windows IP-configuration" 
	DetailPrint "" 
	IpConfig::GetHostName
	!InsertMacro ShowResult "     Host Name.......................:" 
	IpConfig::GetPrimaryDNSSuffix
	!InsertMacro ShowResult "     Primary DNS Suffix..............:" 
	IpConfig::GetNodeType
	!InsertMacro ShowResult "     Node Type.......................:" 
	IpConfig::IsIPRoutingEnabled
	!InsertMacro ShowResult "     IP Routing Enabled..............:" 
	IpConfig::IsWINSProxyEnabled
	!InsertMacro ShowResult "     WINS Proxy Enabled..............:" 
	IpConfig::GetDNSSuffixSearchList
	!InsertMacro ShowResult "     DNS Suffix Search List..........:" 
	DetailPrint "" 
	GetFunctionAddress $2 EnabledAdaptersCallback
	IpConfig::GetEnabledNetworkAdaptersIDsCB $2 
	!InsertMacro ShowMultiResult "     GetEnabledNetworkAdaptersIDs:" 
SectionEnd 
 
Function EnabledAdaptersCallback
	Pop $3 
	IpConfig::GetNetworkAdapterType $3 
	Pop $4 
	Pop $5 
	IpConfig::GetNetworkAdapterConnectionID $3 
	Pop $4 
	Pop $6 
	DetailPrint "$5 adapter $6" 
	IpConfig::GetNetworkAdapterConnectionSpecificDNSSuffix $3 
	!InsertMacro ShowResult "     Connection-specific DNS Suffix..:" 
	IpConfig::GetNetworkAdapterDescription $3 
	!InsertMacro ShowResult "     Description.....................:" 
	IpConfig::GetNetworkAdapterMACAddress $3 
	!InsertMacro ShowResult "     Physical Address................:" 
	IpConfig::IsNetworkAdapterDHCPEnabled $3 
	!InsertMacro ShowResult "     DHCP Enabled....................:" 
	StrCpy $6 $1 
	IpConfig::IsNetworkAdapterAutoSense $3 
	!InsertMacro ShowResult "     Autoconfiguration Enabled.......:" 
	StrCpy $R0 0 
	GetFunctionAddress $4 IPAddressesCallback
	IpConfig::GetNetworkAdapterIPAddressesCB $3 $4 
	!InsertMacro ShowMultiResult "     GetEnabledNetworkAdaptersIPAddresses:" 
	StrCpy $R0 0 
	GetFunctionAddress $4 IPSubNetsCallback
	IpConfig::GetNetworkAdapterIPSubNetsCB $3 $4 
	!InsertMacro ShowMultiResult "     GetNetworkAdapterIPSubNets:" 
	StrCpy $R0 0 
	GetFunctionAddress $4 DefaultIPGatewaysCallback
	IpConfig::GetNetworkAdapterDefaultIPGatewaysCB $3 $4 
	!InsertMacro ShowMultiResult "     GetNetworkAdapterDefaultIPGateways:" 
	${If} $6 == "Yes" 
		IpConfig::GetNetworkAdapterDHCPServer $3 
		!InsertMacro ShowResult "     DHCP Server.....................:" 
	${EndIf} 
	StrCpy $R0 0 
	GetFunctionAddress $4 DNSServersCallback
	IpConfig::GetNetworkAdapterDNSServersCB $3 $4 
	!InsertMacro ShowMultiResult "     GetNetworkAdapterDNSServers:" 
	IpConfig::GetNetworkAdapterPrimaryWINSServer $3 
	!InsertMacro ShowResult "     Primary WINS Server.............:" 
	IpConfig::GetNetworkAdapterSecondaryWINSServer $3 
	!InsertMacro ShowResult "     Secondary WINS Server...........:" 
	${If} $6 == "Yes" 
		IpConfig::GetNetworkAdapterDHCPLeaseObtained $3 
		!InsertMacro ShowResult "     Lease Obtained..................:" 
		IpConfig::GetNetworkAdapterDHCPLeaseExpires $3 
		!InsertMacro ShowResult "     Lease Expires...................:" 
	${EndIf} 
	DetailPrint "" 
FunctionEnd 
 
Function IPAddressesCallback
	Pop $5 
	${if} $R0 == 0 
		DetailPrint "     IP Address......................: $5" 
		IntOp $R0 $R0 + 1 
	${Else} 
		DetailPrint "                                       $5" 
	${EndIf} 
FunctionEnd 
 
Function IPSubNetsCallback
	Pop $5 
	${if} $R0 == 0 
		DetailPrint "     Subnet Mask.....................: $5" 
		IntOp $R0 $R0 + 1 
	${Else} 
		DetailPrint "                                       $5" 
	${EndIf} 
FunctionEnd 
 
Function DefaultIPGatewaysCallback
	Pop $5 
	${if} $R0 == 0 
		DetailPrint "     Default Gateway.................: $5" 
		IntOp $R0 $R0 + 1 
	${Else} 
		DetailPrint "                                       $5" 
	${EndIf} 
FunctionEnd 
 
Function DNSServersCallback
	Pop $5 
	${if} $R0 == 0 
		DetailPrint "     DNS Servers.....................: $5" 
		IntOp $R0 $R0 + 1 
	${Else} 
		DetailPrint "                                       $5" 
	${EndIf} 
FunctionEnd

[edit] nsDialogs example without using callbacks

This example creates a custom nsDialogs Page with a droplist containing all enabled network adapters.
Two textboxes contains the MAC address and all IP adresses from the selected network adapter.
Page custom TestIpConfigInit
 
!insertmacro MUI_PAGE_INSTFILES 
!insertmacro MUI_LANGUAGE English
 
Var DropList
var Dialog
var MACAddress
var IPAddress
 
Section 
SectionEnd 
 
Function TestIpConfigInit
	nsDialogs::Create 1018 
	Pop $Dialog 
 
	${NSD_CreateDropList} 20 20 90% 48u "" 
	Pop $DropList 
	GetFunctionAddress $0 DropList_Changed
	nsDialogs::OnChange $DropList $0 
	IpConfig::GetEnabledNetworkAdaptersIDs
	Pop $0 
	Pop $0 
	StrCpy $2 0 
	StrCpy $4 0 
	ClearErrors 
	${Do} 
		StrCpy $3 $0 
		${WordFind} "$0" " " "+1{" $R0 ; Get next AdapterID from the Id string 
		IpConfig::GetNetworkAdapterDescription $R0 
		Pop $1 
		Pop $1 
		${If} $2 == 0 
			StrCpy $2 $1 ; remember the first entry to show as first 
			StrCpy $4 $R0 
		${EndIf} 
		${NSD_CB_AddString} $DropList $1 
		${WordReplace} "$0" "$R0 " "" "E+1" $0 
	${LoopUntil} ${Errors} 
	ClearErrors 
	${NSD_CB_SelectString} $DropList $2 
	${NSD_CreateLabel} 20 62 80 12u "MAC Address" 
	Pop $1 
	IpConfig::GetNetworkAdapterMACAddress $4 
	Pop $1 
	Pop $1 
	${NSD_CreateText} 120 60 180 12u "$1" 
	Pop $MACAddress 
	${NSD_CreateLabel} 20 82 80 12u "IP Address" 
	Pop $1 
	IpConfig::GetNetworkAdapterIPAddresses $4 
	Pop $1 
	Pop $1 
	${NSD_CreateText} 120 80 180 12u "$1" 
	Pop $IPAddress 
	nsDialogs::Show
FunctionEnd
 
Function DropList_Changed
	${NSD_GetText} $DropList $0 
	IpConfig::GetNetworkAdapterIDFromDescription $0 
	Pop $1 
	Pop $1 
	IpConfig::GetNetworkAdapterMACAddress $1 
	Pop $2 
	Pop $3 
	${NSD_SetText} $MACAddress "$3" 
	IpConfig::GetNetworkAdapterIPAddresses $1 
	Pop $2 
	Pop $3 
	${NSD_SetText} $IPAddress "$3" 
FunctionEnd

[edit] Find MAC address for a given IP address

	IpConfig::GetNetworkAdapterIDFromIPAddress "192.168.1.33" 
	Pop $0 
	Pop $1 
	StrCmp $0 "ok" 0 error
	IpConfig::GetNetworkAdapterMACAddress $1 
	Pop $0 
	Pop $2 
	DetailPrint "MACAddress from adapter #$1: $2" 
	Goto end
error:
	DetailPrint "$1" 
end:

[edit] Version History

[version 0.1: 2009-07-24]

- Initial version.


JP de Ruiter