Using PHP to report an active network interface

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

I use this script, after I determine what available interfaces the computer has, to report which interfaces are active.

# input String ("en0")
# output "NULL or "Active" 
function check_interface_activity($interface){
  @exec('ifconfig| awk \'/flags=|media|inet / {if (substr($2, 1, 6) == "flags=") printf("\n%s ", $1);
  else if ($1 == "inet") printf("%s ", $2);
  else if ($1 == "media:") printf(substr($0, 9))}\' | awk \'$1 ~ /^'.$interface.'/\' | awk \'{print $7}\'',$retval);
 return $retval[0];
} // end check_interface
echo check_interface($interface);

Comments are closed.

Join the mailing list

Check your email and confirm the subscription