note 34796 modified in function.ip2long by danbrown

From: Date: Fri, 05 Dec 2008 13:46:59 +0000
Subject: note 34796 modified in function.ip2long by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147709@lists.php.net to get a copy of this message
If you want to get the interface of an IP, based on the local route table, use this. <?php function GetIfaceforIP($user_ip) { $route = "/bin/netstat -rn"; exec($route, $aoutput); foreach($aoutput as $key => $line) { if($key > 1) { $line = ereg_replace("[[:space:]]+",",",$line); list($network, $gateway, $mask, $flags, $mss, $window, $irtt, $iface) = explode(",", $line) if((ip2long($user_ip) & ip2long($mask)) == ip2long($network)) { return $iface; } } } } ?> --was-- If you want to get the interface of an IP, based on the local route table, use this. function GetIfaceforIP($user_ip) { $route = "/bin/netstat -rn"; exec($route, $aoutput); foreach($aoutput as $key => $line) { if($key > 1) { $line = ereg_replace("[[:space:]]+",",",$line); list($network, $gateway, $mask, $flags, $mss, $window, $irtt, $iface) = explode(",", $line) if((ip2long($user_ip) & ip2long($mask)) == ip2long($network)) { return $iface; } } } } http://php.net/manual/en/function.ip2long.php

« previous php.notes (#147709) next »