Skip to main content
Question

Check whether a machine has a static IP or DHCP

  • November 15, 2017
  • 2 replies
  • 7 views

Forum|alt.badge.img+3

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

mm2270
Forum|alt.badge.img+24
  • Legendary Contributor
  • 7886 replies
  • November 15, 2017

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.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 2 replies
  • November 16, 2017

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