Skip to content

Instantly share code, notes, and snippets.

@wkw
Last active March 28, 2020 04:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wkw/01dab92afaf95ec3f83ec1e11431ec9c to your computer and use it in GitHub Desktop.
Save wkw/01dab92afaf95ec3f83ec1e11431ec9c to your computer and use it in GitHub Desktop.
Mac OS Get Wi-Fi IP address (cmd line or php)
<?php
# SOURCE: https://apple.stackexchange.com/a/226880
$ip = trim(exec("ipconfig getifaddr $(networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}')", $out, $rc));
echo "$ip\n";
#!/usr/bin/env bash
# SOURCE: https://apple.stackexchange.com/a/226880
ipAddress="$(ipconfig getifaddr $(networksetup -listallhardwareports | awk '/Hardware Port: Wi-Fi/{getline; print $2}'))"
echo "Wi-Fi IP = $ipAddress"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment