Check whether a machine has a static IP or DHCP

EdRamos
New Contributor

Hello All,

Is there a way to check whether a machine has a static IP or is getting an IP via DHCP in the JSS? Any info is greatly appreciated.

Thanks!
Ed

2 REPLIES 2

mm2270
Legendary Contributor III

Here's an Extension Attribute script that should give you this info. It may not always be 100% reliable just due to needing to use system_profiler. There may be a better binary that can get this info, but I'm not sure at the moment

#!/bin/bash

interface=$(netstat -rn 2>&1 | grep -m1 "default" | awk '{print $NF}')
interface_name=$(networksetup -listallhardwareports | grep -B1 "$interface" | awk -F': ' '/Hardware Port/{print $NF}')
interface_config=$(system_profiler SPNetworkDataType | grep -B2 "ConfirmedInterfaceName: $interface" | awk '/Configuration Method/{print $NF}')

echo "<result>${interface_name}: $interface_config</result>"

It should print back something like
Wi-Fi: DHCP
or
Apple USB Ethernet Adapter: Static
etc.
If you need an explanation of how this all works or what it's doing, post back and I will add details.

EdRamos
New Contributor

Thanks so much for the response! I will try this out and post my results.