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
Find MAC address
1 |
networksetup -listallhardwareports |
Execute the script above to list the MAC address of all hardware ports of the macOS device.

1 |
networksetup -listallhardwareports |
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

Find IP address
1 |
ipconfig getifaddr <interface> |
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

View network info
The command below will display a brief overview of the device’s network information.
1 |
ifconfig |

View the subnet mask of en0:
1 |
ipconfig getoption en0 subnet_mask |

View the DNS server for en0:
1 |
ipconfig getoption en0 domain_name_server |

View port info
The below command returns only TCP connections on a remote Mac, including open and active ports.
1 |
netstat -ap TCP |

Executing the command below will retrieve the open ports with the keyword “LISTEN”.
1 |
netstat -a | grep -i "LISTEN" |
You can replace LISTEN
with other keywords to modify the result. Examples of different keywords are ESTABLISHED
and TIME_WAIT
.

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.
1 |
arp -a |
