bash - Is it possible to find which network interface client is connected to with PHP? -


i want find network interface client connected on. possible?

if possible bash or scripting language. acceptable me.

i working on freebsd.

here how code should like.

function get_connected_interface(){ //... } echo get_connected_interface(); //should print network interface. example em0 

if using apache, php setting $_server["server_addr"] destination ip address client connected te server.

if using nginx, lighttpd or other webserver, @ result of page <?php phpinfo(); ?> know how ip address of destination (one of ip addresses of server)

in case, use php script launch ifconfig , search interface having ip address.

i'd :

function get_connected_interface() {   static $interfaces=array();   if (!count($interfaces)) {     $curif="";     // launch ifconfig , parse result (inet/inet6)     // @ first function call     exec("ifconfig",$out);     foreach($out $line) {       if (preg_match("#^([a-z0-9\.]*): #",$line,$mat)) {     $curif=$mat[1];       }       if (preg_match("#inet ([0-9\.]*) #",$line,$mat)) {     $interfaces[$mat[1]]=$curif;       }       if (preg_match("#inet6 ([0-9a-fa-f:]*) #",$line,$mat)) {     $interfaces[$mat[1]]=$curif;       }     }   }   return $interfaces[$_server["server_addr"]]; } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -