umarzuki 78 Report post Posted July 29, 2015 aku nak guna kod class kat http://smart-pad.blogspot.com/2006/08/get-all-available-network-interfaces.htmlmacam mana kod php yang aku perlu buat untuk senaraikan ip dari function get_interfaces() ? Quote Share this post Link to post Share on other sites
FryShadow 90 Report post Posted August 3, 2015 Boleh cuba print_r pada object $this->interfacesprint_r($this->interfaces); Quote Share this post Link to post Share on other sites
umarzuki 78 Report post Posted August 3, 2015 (edited) result:blank page kat ip.phpaku dapat error ni kat error.log apachePHP Fatal error: Using $this when not in object context in /var/www/html/ip.phpkod ip.php<?php class networkInterfaces { var $osName; var $interfaces; function networkInterfaces() { $this->osName = strtoupper(PHP_OS); } function get_interfaces() { if ($this->interfaces){ return $this->interfaces; } switch ($this->osName) { case 'WINNT': $ipRes = shell_exec('ipconfig'); $ipPattern = '/IP Address[^:]+: ' . '([\d]{1,3}\.[\d]' . '{1,3}\.[\d]{1,3}' . '\.[\d]{1,3})/'; break; case 'LINUX': $ipRes = shell_exec('ifconfig'); $ipPattern = '/inet addr:([\d]' . '{1,3}\.[\d]{1,3}' . '\.[\d]{1,3}\.' . '[\d]{1,3})/'; break; default : break; } if (preg_match_all($ipPattern, $ipRes, $matches)) { $this->interfaces = $matches[1]; return $this->interfaces; } } } print_r($this->interfaces); ?> kemudian bila aku tukarprint_r($this->interfaces);kepada$inst = new networkInterfaces(); print_r($inst->get_interfaces());ada la keluar array IP network interface (eth1, eth0 & lo)Array ( [0] => 10.0.2.15 [1] => 192.168.56.216 [2] => 127.0.0.1 ) Edited August 3, 2015 by umarzuki Quote Share this post Link to post Share on other sites
FryShadow 90 Report post Posted August 4, 2015 Yup, kalau untuk call class baru$inst = new networkInterfaces();So lepas dah list all interface dengan IP,apa code seterusnya Quote Share this post Link to post Share on other sites
umarzuki 78 Report post Posted August 4, 2015 macam mana nak keluarkan IP sahaja?ada spesifik function/API yang boleh guna untuk list nework interface dan IP? dengan ikut contoh dari http://php.net/manual/en/control-structures.foreach.phpaku cuba senaraikan satu persatu IP tapi dapat error "PHP Notice: Array to string conversion in /var/www/html/ip.php"$arr = array($inst->get_interfaces()); reset($arr); while (list($key, $value) = each($arr)) { print_r($value); } Quote Share this post Link to post Share on other sites