Category filter

Script to get network info on Mac

The Network option in the System Preferences provides the basic network information about the macOS device. Alternatively, you can also use scripts to obtain the network-specific details of Mac. Hexnode’s Execute Custom Script action lets you deploy these scripts to fetch the network info of remote macOS devices in bulk.

Scripting language – Bash

File extension – .sh

Disclaimer:


The sample scripts provided below are adapted from third-party open-source sites.

Find MAC address

Execute the script above to list the MAC address of all hardware ports of the macOS device.

MAC address of all hardware ports

Replace <hardware port> with the hardware port to display the MAC address of the hardware port provided. en0 refers to the device’s physical network interfaces. Most new macOS devices will have en0 as the Wi-Fi connection and en1 as the wired connection.

For example, networksetup -getmacaddress en0

MAC address of the hardware port en0

Find IP address

For Wi-Fi, replace <interface> with en0, and the device’s local IP address will be retrieved. Replace <interface> with en1, and the local IP address of the wired connection of the device will be fetched.

For example, ipconfig getifaddr en0

IP address of the hardware port en0

View network info

The command below will display a brief overview of the device’s network information.

Network info of the device

View the subnet mask of en0:

Subnet mask of the hardware port en0

View the DNS server for en0:

DNS server of the hardware port en0

View port info

The below command returns only TCP connections on a remote Mac, including open and active ports.

Port info of all the internet connections

Executing the command below will retrieve the open ports with the keyword “LISTEN”.

You can replace LISTEN with other keywords to modify the result. Examples of different keywords are ESTABLISHED and TIME_WAIT.

List of open ports with keyword ‘LISTEN’

Display ARP table

The Address Resolution Protocol (ARP) is a utility that displays the Internet-to-Ethernet address translation tables. Every line displays the IP address and the corresponding physical MAC address of each host on the network. Execute the script below to display the ARP table.

ARP table of the device
Notes:

  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository