Analysis to collect IP, MAC Address, and DHCP Status for Mac Computers

Do you mean that you don’t want the Interface Dictionary?

It would be helpful if you posted an example preferences.plist that has the issue of multiple items and tell me which part you want to get. You can redact any specific info, just keep the keys.

I labeled it as well, as it gets a bit crazy. Here is what I was thinking. It seems like everything is already here, i just don’t know how to glue it all together. Any help is VERY appreciated!

  1. Get the “CurrentSet”
    2 & 3) Get the service ID’s for that set.
    4 & 5) Look at those specific services and search for…
  2. Dictionary which has the “current internet connection” listed under “DeviceName” and
  3. Return the string of “ConfigMethod” for the dictionary, which should be the current connection’s information.

Makes total sense, right? HAHAHAHAHAHAHA It’s crazy complicated I know.

1 Like

Ah, okay.

It is hard to see how these all fit together when my machine does not have a bunch of those.

Here are the service IDs for the current set: (#3)

keys of dictionaries "Service" of dictionaries "Network" of dictionaries of values of entries whose((unique value of (following texts of firsts "/Sets/" of it) of strings "CurrentSet" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")= key of it) of dictionaries "Sets" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist"

Here is #4&5: (this is the keys only, but entries are needed to do the filtering and further examination)

keys of dictionaries "NetworkServices" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist"

This should be the set of NetworkServices keys that are in the current set:

keys of entries whose( key of it is contained by set of ( keys of dictionaries "Service" of dictionaries "Network" of dictionaries of values of entries whose((unique value of (following texts of firsts "/Sets/" of it) of strings "CurrentSet" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")= key of it) of dictionaries "Sets" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist" ) ) of dictionaries "NetworkServices" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist"
1 Like

Final Answer:

strings "ConfigMethod" of dictionaries "IPv4" of dictionaries of values of entries whose( ( (name of primary internet connection) = unique value of strings "DeviceName" of dictionaries "Interface" of dictionaries of values of it) AND key of it is contained by set of ( keys of dictionaries "Service" of dictionaries "Network" of dictionaries of values of entries whose((unique value of (following texts of firsts "/Sets/" of it) of strings "CurrentSet" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")= key of it) of dictionaries "Sets" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist" ) ) of dictionaries "NetworkServices" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist"
1 Like

holy cow.

I want to flood this message with emoticons of joy! :+1: :joy:

Thank you so much. I’m going to go dissect this now so I can better understand it.

2 Likes

Up above are many of the pieces of the relevance used to build up to the final answer, but to really understand it all, you really need to start with the “end” and work backwards.

This is what you want, but for all, unfiltered:

strings "ConfigMethod" of dictionaries "IPv4" of dictionaries of values of entries of dictionaries "NetworkServices" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist"

the result on my system:

A: DHCP
A: PPP
A: DHCP
A: DHCP
A: DHCP
A: DHCP

The final answer is the same, just filtering out everything except for the current connection in the current set.

The screenshot you provided was very helpful to help me figure out what needed to be filtered out, why, and how to go about it.

1 Like

Being as OS X lacks an inspector for “dhcp enabled of network adapter”, I’m trying to adapt this to confirm whether an adapter in the current set is both Ethernet and DHCP.

This returns the adapters…

((( keys of dictionaries "Service" of dictionaries "Network" of dictionaries of values of entries whose ( (unique value of (following texts of firsts "/Sets/" of it) of strings "CurrentSet" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")= key of it) of dictionaries "Sets" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist" ) ) of dictionaries "NetworkServices" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")

…but how should I constrain it? I get the idea it should be something like "key whose ( (dictionary “Inferface” of it contains string “Ethernet” of key “Type”) and (dictionary “IPv4” of it contains string “DHCP” of key “ConfigMethod”) ) … but I can’t quite suss it out.

I adapted this to return on machines using DHCP on a particular subnet:

exists match (regex "Automatic|DHCP") of (strings "ConfigMethod" of dictionaries "IPv4" of dictionaries of values of entries whose( ( (name of (adapters of network) whose (cidr string of it = "127.0.0.0/24")) = unique value of strings "DeviceName" of dictionaries "Interface" of dictionaries of values of it) AND key of it is contained by set of ( keys of dictionaries "Service" of dictionaries "Network" of dictionaries of values of entries whose((unique value of (following texts of firsts "/Sets/" of it) of strings "CurrentSet" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")= key of it) of dictionaries "Sets" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist" ) ) of dictionaries "NetworkServices" of dictionaries of files "/Library/Preferences/SystemConfiguration/preferences.plist")

(“127.0.0.0/24” is a placeholder, of course. Change as needed.)