Retrieving a "Primary IP Address"

(imported topic written by BenKus)

Many computers have multiple network adapters and IP addresses and BigFix will give you all of them in no particular order in the network properties. Sometimes our customers ask us about getting the “Primary IP” from the system, which we think they mean the IP address that the computer is using to communicate with the BigFix Relay (which likely is the IP address that is most significant to internal company uses). Up until BigFix 7.1, we did not have this capability.

In BigFix 7.1, we implemented some wake-on-lan enhancements that made it necessary for the agent to track with IP address it was using talk to its relay and we made this information inspectable in relevance. So a nice by-product of the 7.1 changes is that you can now figure out the “Primary IP” (or at least the IP address used to talk to the relay).

Here is the relevance you can use to retrieve the Primary IP:

addresses of adapters whose (cidr string of it = wake on lan subnet cidr string) of network

(Note that this needs to be evaluated as the BES Client so it won’t work in QnA and you will need to use the Client API Tester (http://forum.bigfix.com/viewtopic.php?id=2756) or put the relevance in a property to get results.)

Here is what you get from this:

  • This property will return the IP address of the network adapter that is being used to talk to the agent’s relay.
  • If you have a lot of ip addresses that aren’t used (such as with VMWare or other unused network devices), then this property can pick the “real IP address”.
  • This property does NOT know about NAT devices so if you have a NAT between you and the relay, this property won’t return to you the IP (maybe we can implement this one day).

Ben

1 Like

(imported comment written by SystemAdmin)

Could you break down the client verstions this works on between the various operating systems?

(imported comment written by BenKus)

I think it works on all agents 7.1+…

Ben

(imported comment written by SystemAdmin)

This might also be helpful in narrowing down the primary addresses where the wake-on-lan code doesn’t work or non-windows systems…

addresses whose (it as string != “0.0.0.0” and (it as string contains “169.”)!=true and it as string starts with (preceding text of last “.” of (addresses of gateway lists whose (address of it != “0.0.0.0”) of adapters whose (address of it != “0.0.0.0”) of network as string))) of ip interfaces whose (loopback of it = false) of network

It filters out all 169 addresses, as well as addrs that do not have a valid gateway address.

(imported comment written by FerryHadiwijaya)

I tried your query, and it works pefectly on full class C subnet (subnet 255.255.255.0).

But how to query Primary IP Address which have subnet in class A or class B, or even in partial class C (i.e 255.255.255.192, etc)?

(imported comment written by BenKus)

http://forum.bigfix.com/viewtopic.php?id=5970

This will only work on Unix-like boxes but you can specify the IP of a specific interface, which traditionally will be the first interface configured. The interface name may vary, for example “eth0” needed to be changed to “eno16” for my CentOS7 workstation. Run “ifconfig” to determine what IP is tied to what interface.

This works for situations where you may have multiple IPs in the same class C subnet on a single server. Note there is no need to filter out loopback using this method.

{address of ip interfaces whose (name of it contains "eth0") of network}