// GetNetIPAddresses returns IP addresses for a particular
// network adapter.
GetNetIPAddresses returns IP addresses for a particular
network adapter.
// GetNetIPAddresses returns IP addresses for a particular // network adapter .
func GetNetIPAddresses(index int) ([]NetIPAddress, error) {
	con, err := wmi.NewStandardCimV2Connection()
	if err != nil {
		return []NetIPAddress{}, err
	}
	defer con.Close()
	q := []wmi.Query{}
	if index != 0 {
		q = []wmi.Query{
			&wmi.AndQuery{
				wmi.QueryFields{
					Key:   "InterfaceIndex",
					Value: index,
					Type:  wmi.Equals},
			},
		}
	}
	result, err := con.Gwmi("MSFT_NetIPAddress", []string{}, q)
	if err != nil {
		return []NetIPAddress{}, err
	}
	ips, err := result.Elements()
	if len(ips) == 0 {
		return []NetIPAddress{}, nil
	}
	ret := make([]NetIPAddress, len(ips))
	for index, ip := range ips {
		s := &NetIPAddress{}
		if err := wmi.PopulateStruct(ip, s); err != nil {
			return []NetIPAddress{}, err
		}
		ret[index] = *s
	}
	return ret, nil
}
func GetNetIPAddresses ( index int ) ( [ ] NetIPAddress , error ) { con , err := wmi . NewStandardCimV2Connection ( ) if err != nil { return [ ] NetIPAddress { } , err } defer con . Close ( ) q := [ ] wmi . Query { } if index != 0 { q = [ ] wmi . Query { & wmi . AndQuery { wmi . QueryFields { Key : " " , Value : index , Type : wmi . Equals } , } , } } result , err := con . Gwmi ( " " , [ ] string { } , q ) if err != nil { return [ ] NetIPAddress { } , err } ips , err := result . Elements ( ) if len ( ips ) == 0 { return [ ] NetIPAddress { } , nil } ret := make ( [ ] NetIPAddress , len ( ips ) ) for index , ip := range ips { s := & NetIPAddress { } if err := wmi . PopulateStruct ( ip , s ) ; err != nil { return [ ] NetIPAddress { } , err } ret [ index ] = * s } return ret , nil }
GetNetIPAddresses returns IP addresses for a particular
network adapter.
GetNetIPAddresses returns IP addresses for a particular network adapter .