Documentation
¶
Overview ¶
Package netw provides network adapter management functionality.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignVariant ¶
AssignVariant assigns a variant to a destination.
Types ¶
type AdapterConfiguration ¶
type AdapterConfiguration struct {
Caption string
Description string
DHCPEnabled bool
DHCPServer string
DNSDomain string
DNSHostName string
DNSServerSearchOrder []string
IPAddress []string
IPEnabled bool
IPSubnet []string
MACAddress string
DefaultIPGateway []string
ServiceName string
SettingID string
InterfaceIndex uint32
// contains filtered or unexported fields
}
AdapterConfiguration represents a Win32_NetworkAdapterConfiguration object.
Ref: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968170(v=vs.85)
func (*AdapterConfiguration) Query ¶
func (n *AdapterConfiguration) Query() error
Query reads and populates the network adapter state from WMI.
func (*AdapterConfiguration) StaticRoute ¶
func (n *AdapterConfiguration) StaticRoute(ipaddress []string, subnetMask []string) error
StaticRoute sets the static route for the network adapter.
IMPORTANT: This method ONLY supports Ipv4.
type AdapterConfigurationSet ¶
type AdapterConfigurationSet struct {
NetworkAdapterConfigurations []AdapterConfiguration
}
An AdapterConfigurationSet contains one or more NetworkAdapterConfigurations.
type CreateIPAddressOptions ¶
type CreateIPAddressOptions struct {
InterfaceIndex uint32
InterfaceAlias string
IPAddress string
AddressFamily uint16
PrefixLength uint8
Type uint8
PrefixOrigin uint8
SuffixOrigin uint8
AddressState uint16
ValidLifetime string // CIM_DATETIME
PreferredLifetime string // CIM_DATETIME
SkipAsSource bool
DefaultGateway string
PolicyStore string
PassThru bool
}
CreateIPAddressOptions represents the options for creating an IP address.
Ref: https://learn.microsoft.com/en-us/windows/win32/fwp/wmi/nettcpipprov/create-msft-netipaddress
type IPAddress ¶
type IPAddress struct {
AddressFamily uint16
AddressState uint16
InterfaceAlias string
InterfaceIndex uint32
IPAddress string
PreferredLifetime string
PrefixOrigin uint16
SkipAsSource bool
Store uint8
SuffixOrigin uint16
Type uint8
ValidLifetime string
// contains filtered or unexported fields
}
IPAddress represents a MSFT_NetIPAddress object.
Ref: https://learn.microsoft.com/en-us/windows/win32/fwp/wmi/nettcpipprov/msft-netipaddress
func (*IPAddress) Create ¶
func (ip *IPAddress) Create(opts CreateIPAddressOptions) (IPOutput, error)
Create creates the IP address on the current instance.
Ref: https://learn.microsoft.com/en-us/windows/win32/fwp/wmi/nettcpipprov/create-msft-netipaddress
type IPAddressSet ¶
type IPAddressSet struct {
IPAddresses []IPAddress
}
IPAddressSet contains one or more IPAddresses.
type NetAdapter ¶
type NetAdapter struct {
// The name of the network adapter. This property is inherited from CIM_ManagedSystemElement.
Name string
// Current status of the object. This property is inherited from CIM_ManagedSystemElement.
Status string
// The availability and status of the device. This property is inherited from CIM_LogicalDevice.
Availability uint16
// If TRUE, the device is using a user-defined configuration. This property is inherited from CIM_LogicalDevice.
ConfigManagerUserConfig bool
// The name of the class or subclass used in the creation of an instance. This property is inherited from CIM_LogicalDevice.
CreationClassName string
// The address or other identifying information for the network adapter. This property is inherited from CIM_LogicalDevice.
DeviceID string
// If TRUE, the error reported in the LastErrorCode property is now cleared. This property is inherited from CIM_LogicalDevice.
ErrorCleared bool
// A string that provides more information about the error recorded in the LastErrorCode property and information about any corrective actions that can be taken. This property is inherited from CIM_LogicalDevice.
ErrorDescription string
// The last error code reported by the logical device. This property is inherited from CIM_LogicalDevice.
LastErrorCode uint32
// The Plug and Play device identifier of the logical device. This property is inherited from CIM_LogicalDevice.
PNPDeviceID string
// An array of the specific power-related capabilities of a logical device. This property is inherited from CIM_LogicalDevice.
PowerManagementCapabilities []uint16
// If TRUE, the device can be power managed. This property is inherited from CIM_LogicalDevice.
PowerManagementSupported bool
// The status of the logical device. This property is inherited from CIM_LogicalDevice.
StatusInfo uint16
// The value of the CreationClassName property for the scoping system. This property is inherited from CIM_LogicalDevice.
SystemCreationClassName string
// The name of the scoping system. This property is inherited from CIM_LogicalDevice.
SystemName string
// The current bandwidth of the port in bits per second.
Speed uint64
// The maximum bandwidth of the port in bits per second.
MaxSpeed uint64
// The requested bandwidth of the port in bits per second.
RequestedSpeed uint64
// In cases where a port can be used for more than one function, this property indicates its primary usage.
UsageRestriction uint16
// The specific type of the port.
PortType uint16
// A string that describes the port type when the PortType property is set to 1 (Other).
OtherPortType string
// The network port type when the PortType property is set to 1 (Other).
OtherNetworkPortType string
// The port number.
PortNumber uint16
// The link technology for the port.
LinkTechnology uint16
// A string that describes the link technology when the LinkTechnology property is set to 1 (Other).
OtherLinkTechnology string
// The network address that is hardcoded into a port.
PermanentAddress string
// An array of network addresses for the port.
NetworkAddresses []string
// If TRUE, the port is operating in full duplex mode.
FullDuplex bool
// If TRUE, the port can automatically determine the speed or other communications characteristics of the attached network media.
AutoSense bool
// The maximum transmission unit (MTU) that can be supported.
SupportedMaximumTransmissionUnit uint64
// The active or negotiated maximum transmission unit (MTU) on the port.
ActiveMaximumTransmissionUnit uint64
// The description of the network interface.
InterfaceDescription string
// The name of the network interface.
InterfaceName string
// The network layer unique identifier (LUID) for the network interface.
NetLuid uint64
// The GUID for the network interface.
InterfaceGUID windows.GUID
// The index for the network interface.
InterfaceIndex uint32
// The name of the device object for the network adapter.
DeviceName string
// The index of the LUID for the network adapter.
NetLuidIndex uint32
// If TRUE, this is a virtual network adapter.
Virtual bool
// If TRUE, this network adapter is not displayed in the user interface.
Hidden bool
// If TRUE, this network adapter cannot be removed by a user.
NotUserRemovable bool
// If TRUE, this is an intermediate driver filter.
IMFilter bool
// The interface type as defined by the Internet Assigned Names Authority (IANA).
InterfaceType uint32
// If TRUE, this is a hardware interface.
HardwareInterface bool
// If TRUE, this is a WDM interface.
WdmInterface bool
// If TRUE, this is an endpoint interface.
EndPointInterface bool
// If TRUE, this is an iSCSI interface.
ISCSIInterface bool
// The current state of the network adapter.
State uint32
// The media type that the network adapter supports.
NdisMedium uint32
// The physical media type of the network adapter.
NdisPhysicalMedium uint32
// The operational status of the network interface.
InterfaceOperationalStatus uint32
// If TRUE, the operational status is down because the default port is not authenticated.
OperationalStatusDownDefaultPortNotAuthenticated bool
// If TRUE, the operational status is down because the media is disconnected.
OperationalStatusDownMediaDisconnected bool
// If TRUE, the operational status is down because the interface is paused.
OperationalStatusDownInterfacePaused bool
// If TRUE, the operational status is down because the interface is in a low power state.
OperationalStatusDownLowPowerState bool
// The administrative status of the network interface.
InterfaceAdminStatus uint32
// The media connect state of the network adapter.
MediaConnectState uint32
// The maximum transmission unit (MTU) size for the network adapter.
MtuSize uint32
// The VLAN identifier for the network adapter.
VlanID uint16
// The transmit link speed for the network adapter.
TransmitLinkSpeed uint64
// The receive link speed for the network adapter.
ReceiveLinkSpeed uint64
// If TRUE, the network adapter is in promiscuous mode.
PromiscuousMode bool
// If TRUE, the device is enabled to wake the system.
DeviceWakeUpEnable bool
// If TRUE, a connector is present on the network adapter.
ConnectorPresent bool
// The duplex state of the media.
MediaDuplexState uint32
// The date of the driver for the network adapter.
DriverDate string
// The date of the driver for the network adapter, in 100-nanosecond intervals.
DriverDateData uint64
// The version of the driver for the network adapter.
DriverVersionString string
// The name of the driver for the network adapter.
DriverName string
// The description of the driver for the network adapter.
DriverDescription string
// The major version of the driver for the network adapter.
MajorDriverVersion uint16
// The minor version of the driver for the network adapter.
MinorDriverVersion uint16
// The major NDIS version of the driver for the network adapter.
DriverMajorNdisVersion uint8
// The minor NDIS version of the driver for the network adapter.
DriverMinorNdisVersion uint8
// The provider of the driver for the network adapter.
DriverProvider string
// The component identifier for the network adapter.
ComponentID string
// The indices of the lower layer interfaces.
LowerLayerInterfaceIndices []uint32
// The indices of the higher layer interfaces.
HigherLayerInterfaceIndices []uint32
// If TRUE, the network adapter is administratively locked.
AdminLocked bool
// contains filtered or unexported fields
}
NetAdapter represents a MSFT_NetAdapter object. It's important to note that some fields are read-only.
Ref: https://learn.microsoft.com/en-us/previous-versions/windows/desktop/legacy/hh968170(v=vs.85)
func (*NetAdapter) Close ¶
func (n *NetAdapter) Close()
Close releases the handle to the network adapter.
func (*NetAdapter) Disable ¶
func (n *NetAdapter) Disable() error
Disable disables the network adapter.
Ref: https://learn.microsoft.com/en-us/windows/win32/fwp/wmi/netadaptercimprov/disable-msft-netadapter
func (*NetAdapter) Enable ¶
func (n *NetAdapter) Enable() error
Enable enables the network adapter.
Ref: https://learn.microsoft.com/en-us/windows/win32/fwp/wmi/netadaptercimprov/enable-msft-netadapter
func (*NetAdapter) Query ¶
func (n *NetAdapter) Query() error
Query reads and populates the network adapter state from WMI.
func (*NetAdapter) Rename ¶
func (n *NetAdapter) Rename(name string) error
Rename renames the network adapter.
Ref: https://learn.microsoft.com/en-us/windows/win32/fwp/wmi/netadaptercimprov/msft-netadapter-rename
type NetAdapterSet ¶
type NetAdapterSet struct {
NetAdapters []NetAdapter
}
A NetAdapterSet contains one or more NetAdapters.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents a connection to the host Storage service (in WMI).
func AdapterConnect ¶
AdapterConnect connects to the WMI provider for managing network adapter objects. You must call Close() to release the provider when finished.
Example: network.AdapterConnect()
func Connect ¶
Connect connects to the WMI provider for managing storage objects. You must call Close() to release the provider when finished.
Example: storage.Connect()
func (*Service) Close ¶
func (svc *Service) Close()
Close frees all resources associated with a volume.
func (Service) GetIPAddresses ¶
func (svc Service) GetIPAddresses(filter string) (IPAddressSet, error)
GetIPAddresses returns a IPAddresses struct.
Get all IP addresses:
svc.GetIPAddresses("")
To get specific IP addresses, provide a valid WMI query filter string, for example:
svc.GetIPAddresses("WHERE IPAddress='192.168.1.1'")
func (Service) GetNetAdapters ¶
func (svc Service) GetNetAdapters(filter string) (NetAdapterSet, error)
GetNetAdapters queries for local network adapters.
Close() must be called on the resulting NetAdapter to ensure all network adapters are released.
Get all network adapters:
svc.GetNetAdapters("")
To get specific network adapters, provide a valid WMI query filter string, for example:
svc.GetNetAdapters("WHERE Name='Wi-Fi'")
func (Service) GetNetworkAdapterConfigurations ¶
func (svc Service) GetNetworkAdapterConfigurations(filter string) (AdapterConfigurationSet, error)
GetNetworkAdapterConfigurations returns an AdapterConfigurationSet.