Using PHP to return an IP address

Posted by | Posted in Code, Command-Line, Functions, OS X, PHP | Posted on 19-07-2009

After I’ve determine which interfaces are active on my computer(s), I can use this script to report back the IP address of said interface.

# input String ("en0")
# output String IP
function get_network_interface_ip($interface) {
  @exec('/usr/sbin/ipconfig getifaddr '. $interface, $retval);
 return $retval[0];
}// end get_network_iterface_ip
echo get_network_interface_ip($interface);

Comments are closed.

Join the mailing list

Check your email and confirm the subscription